提交 96f59ffb 编写于 作者: A Annie_wang

Update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 aef3a217
...@@ -504,8 +504,8 @@ For details about the error codes, see [Application Access Control Error Codes]( ...@@ -504,8 +504,8 @@ For details about the error codes, see [Application Access Control Error Codes](
| ID| Error Message| | ID| Error Message|
| -------- | -------- | | -------- | -------- |
| 12100001 | The parameter is invalid. The tokenID in list is all invalid, or the permissionName in list is all invalid. | | 12100001 | The parameter is invalid. The tokenIDs or permissionNames in the list are all invalid. |
| 12100004 | The API is not used together with "on()". | | 12100004 | The interface is not used together with "on". |
| 12100007 | Service is abnormal. | | 12100007 | Service is abnormal. |
| 12100008 | Out of memory. | | 12100008 | Out of memory. |
...@@ -532,7 +532,9 @@ verifyAccessToken(tokenID: number, permissionName: Permissions): Promise&lt;Gran ...@@ -532,7 +532,9 @@ verifyAccessToken(tokenID: number, permissionName: Permissions): Promise&lt;Gran
Verifies whether a permission is granted to an application. This API uses a promise to return the result. Verifies whether a permission is granted to an application. This API uses a promise to return the result.
> **NOTE**<br>You are advised to use [checkAccessToken](#checkaccesstoken9). > **NOTE**
>
> You are advised to use [checkAccessToken](#checkaccesstoken9).
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
...@@ -619,7 +621,7 @@ Requests permissions from the user in a dialog box. This API uses a promise to ...@@ -619,7 +621,7 @@ Requests permissions from the user in a dialog box. This API uses a promise to
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| context | Context | Yes| Ability context of the application that requests the permissions. | | context | Context | Yes| Ability context of the application that requests the permissions. |
| permissionList | Array&lt;Permissions&gt; | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md). | | permissionList | Array&lt;Permissions&gt; | Yes| Permissions requested. For details about the permissions, see the [Application Permission List](../../security/permission-list.md).|
**Return value** **Return value**
...@@ -659,7 +661,9 @@ verifyAccessToken(tokenID: number, permissionName: string): Promise&lt;GrantStat ...@@ -659,7 +661,9 @@ verifyAccessToken(tokenID: number, permissionName: string): Promise&lt;GrantStat
Verifies whether a permission is granted to an application. This API uses a promise to return the result. Verifies whether a permission is granted to an application. This API uses a promise to return the result.
> NOTE<br>This API is deprecated since API version 9. You are advised to use [checkAccessToken](#checkaccesstoken9). > **NOTE**
>
> This API is no longer maintained since API version 9. You are advised to use [checkAccessToken](#checkaccesstoken9).
**System capability**: SystemCapability.Security.AccessToken **System capability**: SystemCapability.Security.AccessToken
......
...@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions: ...@@ -8,7 +8,7 @@ The **relationalStore** module provides the following functions:
- [RdbStore](#rdbstore): provides APIs for managing data in an RDB store. - [RdbStore](#rdbstore): provides APIs for managing data in an RDB store.
- [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store. - [Resultset](#resultset): provides APIs for accessing the result set obtained from the RDB store.
> **NOTE**<br/> > **NOTE**
> >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...@@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul ...@@ -30,7 +30,7 @@ Obtains an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description | | 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-ability-context.md).| | 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).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
| callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes | Callback invoked to return the RDB store obtained. | | callback | AsyncCallback&lt;[RdbStore](#rdbstore)&gt; | Yes | Callback invoked to return the RDB store obtained. |
...@@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set ...@@ -108,7 +108,7 @@ Obtains an RDB store. This API uses a promise to return the result. You can set
| Name | Type | Mandatory| Description | | 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-ability-context.md).| | 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).|
| config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. | | config | [StoreConfig](#storeconfig) | Yes | Configuration of the RDB store. |
**Return value** **Return value**
...@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul ...@@ -188,7 +188,7 @@ Deletes an RDB store. This API uses an asynchronous callback to return the resul
| Name | Type | Mandatory| Description | | 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-ability-context.md).| | 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 RDB store to delete. | | name | string | Yes | Name of the RDB store to delete. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. |
...@@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise to return the result. ...@@ -249,7 +249,7 @@ Deletes an RDB store. This API uses a promise to return the result.
| Name | Type | Mandatory| Description | | 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-ability-context.md).| | 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 RDB store to delete. | | name | string | Yes | Name of the RDB store to delete. |
**Return value** **Return value**
...@@ -2612,9 +2612,9 @@ Synchronizes data between devices. This API uses a promise to return the result. ...@@ -2612,9 +2612,9 @@ Synchronizes data between devices. This API uses a promise to return the result.
let predicates = new relationalStore.RdbPredicates('EMPLOYEE'); let predicates = new relationalStore.RdbPredicates('EMPLOYEE');
predicates.inDevices(['12345678abcde']); predicates.inDevices(['12345678abcde']);
let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates); let promise = store.sync(relationalStore.SyncMode.SYNC_MODE_PUSH, predicates);
promise.then((resultSet) =>{ promise.then((result) =>{
console.info(`Sync done.`); console.info(`Sync done.`);
for (let i = 0; i < resultSet.length; i++) { for (let i = 0; i < result.length; i++) {
console.info(`device= ${result[i][0]}, status= ${result[i][1]}`); console.info(`device= ${result[i][0]}, status= ${result[i][1]}`);
} }
}).catch((err) => { }).catch((err) => {
...@@ -2693,10 +2693,12 @@ Provides APIs to access the result set obtained by querying the RDB store. A res ...@@ -2693,10 +2693,12 @@ Provides APIs to access the result set obtained by querying the RDB store. A res
Obtain the **resultSet** object first. Obtain the **resultSet** object first.
```js ```js
let resultSet = null;
let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
predicates.equalTo("AGE", 18); predicates.equalTo("AGE", 18);
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((result) => {
resultSet = result;
console.info(`resultSet columnNames: ${resultSet.columnNames}`); console.info(`resultSet columnNames: ${resultSet.columnNames}`);
console.info(`resultSet columnCount: ${resultSet.columnCount}`); console.info(`resultSet columnCount: ${resultSet.columnCount}`);
}); });
...@@ -2867,7 +2869,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode ...@@ -2867,7 +2869,7 @@ For details about the error codes, see [RDB Error Codes](../errorcodes/errorcode
let predicates = new relationalStore.RdbPredicates("EMPLOYEE"); let predicates = new relationalStore.RdbPredicates("EMPLOYEE");
let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]); let promise = store.query(predicates, ["ID", "NAME", "AGE", "SALARY", "CODES"]);
promise.then((resultSet) => { promise.then((resultSet) => {
resultSet.(5); resultSet.goToRow(5);
resultSet.close(); resultSet.close();
}).catch((err) => { }).catch((err) => {
console.error(`query failed, err: ${err}`); console.error(`query failed, err: ${err}`);
......
...@@ -86,8 +86,8 @@ For details about the error codes, see [Enterprise Device Management Error Codes ...@@ -86,8 +86,8 @@ For details about the error codes, see [Enterprise Device Management Error Codes
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
| 9200001 | The application is not an administrator application of the device. | | 9200001 | The application is not an administrator application of the device. |
| 9200002 | The administrator application does not have permission to manage the device.| | 9200002 | The administrator application does not have permission to manage the device. |
**Example** **Example**
......
...@@ -16,7 +16,7 @@ import fs from '@ohos.file.fs'; ...@@ -16,7 +16,7 @@ import fs from '@ohos.file.fs';
## Guidelines ## Guidelines
Before using the APIs provided by this module to perform operations on files or directories, obtain the path of the file or directory in the application sandbox as follows: Before using the APIs provided by this module to perform operations on files or folders, obtain the path of the file or directory in the application sandbox as follows:
**Stage Model** **Stage Model**
...@@ -60,14 +60,14 @@ Obtains detailed file information. This API uses a promise to return the result. ...@@ -60,14 +60,14 @@ Obtains detailed file information. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the file information obtained.|
**Example** **Example**
```js ```js
let filePath = pathDir + "test.txt"; let filePath = pathDir + "/test.txt";
fs.stat(filePath).then((stat) => { fs.stat(filePath).then((stat) => {
console.info("get file info succeed, the size of file is " + stat.size); console.info("get file info succeed, the size of file is " + stat.size);
}).catch((err) => { }).catch((err) => {
...@@ -119,9 +119,9 @@ Obtains detailed file information synchronously. ...@@ -119,9 +119,9 @@ Obtains detailed file information synchronously.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
**Example** **Example**
...@@ -146,9 +146,9 @@ Checks whether a file exists. This API uses a promise to return the result. ...@@ -146,9 +146,9 @@ Checks whether a file exists. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;boolean&gt; | Promise used to return a Boolean value.| | Promise&lt;boolean&gt; | Promise used to return a Boolean value.|
**Example** **Example**
...@@ -233,15 +233,15 @@ Closes a file. This API uses a promise to return the result. ...@@ -233,15 +233,15 @@ Closes a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.| | file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -266,10 +266,10 @@ Closes a file. This API uses an asynchronous callback to return the result. ...@@ -266,10 +266,10 @@ Closes a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------ | | -------- | ------------------------- | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.| | file | [File](#file)\|number | Yes | File object or FD of the file to close.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is closed asynchronously.|
**Example** **Example**
...@@ -295,9 +295,9 @@ Synchronously closes a file. ...@@ -295,9 +295,9 @@ Synchronously closes a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| file | [File](#file)\|number | Yes | File object or FD of the file to close.| | file | [File](#file)\|number | Yes | File object or FD of the file to close.|
**Example** **Example**
...@@ -317,23 +317,23 @@ Copies a file. This API uses a promise to return the result. ...@@ -317,23 +317,23 @@ Copies a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. | | src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. | | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.| | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file of the same name.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let srcPath = pathDir + "srcDir/test.txt"; let srcPath = pathDir + "/srcDir/test.txt";
let dstPath = pathDir + "dstDir/test.txt"; let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFile(srcPath, dstPath).then(() => { fs.copyFile(srcPath, dstPath).then(() => {
console.info("copy file succeed"); console.info("copy file succeed");
}).catch((err) => { }).catch((err) => {
...@@ -351,18 +351,18 @@ Copies a file. This API uses an asynchronous callback to return the result. ...@@ -351,18 +351,18 @@ Copies a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------------------------- | ---- | ---------------------------------------- | | -------- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. | | src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. | | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is copied asynchronously. |
**Example** **Example**
```js ```js
let srcPath = pathDir + "srcDir/test.txt"; let srcPath = pathDir + "/srcDir/test.txt";
let dstPath = pathDir + "dstDir/test.txt"; let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFile(srcPath, dstPath, (err) => { fs.copyFile(srcPath, dstPath, (err) => {
if (err) { if (err) {
console.info("copy file failed with error message: " + err.message + ", error code: " + err.code); console.info("copy file failed with error message: " + err.message + ", error code: " + err.code);
...@@ -383,17 +383,17 @@ Synchronously copies a file. ...@@ -383,17 +383,17 @@ Synchronously copies a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | -------------------------- | ---- | ---------------------------------------- | | ---- | -------------------------- | ---- | ---------------------------------------- |
| src | string\|number | Yes | Path or FD of the file to copy. | | src | string\|number | Yes | Path or FD of the file to copy. |
| dest | string\|number | Yes | Destination path of the file or FD of the file created. | | dest | string\|number | Yes | Destination path of the file or FD of the file created. |
| mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.| | mode | number | No | Whether to overwrite the file of the same name in the destination path. The default value is **0**, which is the only value supported.<br>**0**: overwrite the file with the same name and truncate the part that is not overwritten.|
**Example** **Example**
```js ```js
let srcPath = pathDir + "srcDir/test.txt"; let srcPath = pathDir + "/srcDir/test.txt";
let dstPath = pathDir + "dstDir/test.txt"; let dstPath = pathDir + "/dstDir/test.txt";
fs.copyFileSync(srcPath, dstPath); fs.copyFileSync(srcPath, dstPath);
``` ```
...@@ -414,14 +414,14 @@ Creates a directory. This API uses a promise to return the result. ...@@ -414,14 +414,14 @@ Creates a directory. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let dirPath = pathDir + '/testDir'; let dirPath = pathDir + "/testDir";
fs.mkdir(dirPath).then(() => { fs.mkdir(dirPath).then(() => {
console.info("Directory created"); console.info("Directory created");
}).catch((err) => { }).catch((err) => {
...@@ -448,7 +448,7 @@ Creates a directory. This API uses an asynchronous callback to return the result ...@@ -448,7 +448,7 @@ Creates a directory. This API uses an asynchronous callback to return the result
**Example** **Example**
```js ```js
let dirPath = pathDir + '/testDir'; let dirPath = pathDir + "/testDir";
fs.mkdir(dirPath, (err) => { fs.mkdir(dirPath, (err) => {
if (err) { if (err) {
console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code); console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
...@@ -476,7 +476,7 @@ Synchronously creates a directory. ...@@ -476,7 +476,7 @@ Synchronously creates a directory.
**Example** **Example**
```js ```js
let dirPath = path + '/testDir'; let dirPath = pathDir + "/testDir";
fs.mkdirSync(dirPath); fs.mkdirSync(dirPath);
``` ```
...@@ -498,9 +498,9 @@ Opens a file. This API uses a promise to return the result. File uniform resourc ...@@ -498,9 +498,9 @@ Opens a file. This API uses a promise to return the result. File uniform resourc
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ----------- | | --------------------- | ----------- |
| Promise&lt;[File](#file)&gt; | Promise used to return the file object.| | Promise&lt;[File](#file)&gt; | Promise used to return the file object.|
**Example** **Example**
...@@ -559,9 +559,9 @@ Synchronously opens a file. File URIs are supported. ...@@ -559,9 +559,9 @@ Synchronously opens a file. File URIs are supported.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ----------- | | ------ | ----------- |
| [File](#file) | File object opened.| | [File](#file) | File object opened.|
**Example** **Example**
...@@ -590,9 +590,9 @@ Reads data from a file. This API uses a promise to return the result. ...@@ -590,9 +590,9 @@ Reads data from a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.| | Promise&lt;number&gt; | Promise used to return the data read.|
**Example** **Example**
...@@ -602,7 +602,7 @@ Reads data from a file. This API uses a promise to return the result. ...@@ -602,7 +602,7 @@ Reads data from a file. This API uses a promise to return the result.
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fs.read(file.fd, buf).then((readLen) => { fs.read(file.fd, buf).then((readLen) => {
console.info("Read file data successfully"); console.info("Read file data successfully");
console.info(String.fromCharCode.apply(null, new Uint8Array(readLen))); console.info(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
fs.closeSync(file); fs.closeSync(file);
}).catch((err) => { }).catch((err) => {
console.info("read file data failed with error message: " + err.message + ", error code: " + err.code); console.info("read file data failed with error message: " + err.message + ", error code: " + err.code);
...@@ -619,12 +619,12 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -619,12 +619,12 @@ Reads data from a file. This API uses an asynchronous callback to return the res
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is read asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is read asynchronously. |
**Example** **Example**
...@@ -637,7 +637,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res ...@@ -637,7 +637,7 @@ Reads data from a file. This API uses an asynchronous callback to return the res
console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code); console.info("mkdir failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
console.info("Read file data successfully"); console.info("Read file data successfully");
console.info(String.fromCharCode.apply(null, new Uint8Array(readLen))); console.info(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
fs.closeSync(file); fs.closeSync(file);
} }
}); });
...@@ -654,17 +654,17 @@ Synchronously reads data from a file. ...@@ -654,17 +654,17 @@ Synchronously reads data from a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer | Yes | Buffer used to store the file data read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file data read. |
| options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.| | options | Object | No | The options are as follows:<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
**Example** **Example**
...@@ -693,14 +693,14 @@ Deletes a directory. This API uses a promise to return the result. ...@@ -693,14 +693,14 @@ Deletes a directory. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let dirPath = pathDir + '/testDir'; let dirPath = pathDir + "/testDir";
fs.rmdir(dirPath).then(() => { fs.rmdir(dirPath).then(() => {
console.info("Directory deleted"); console.info("Directory deleted");
}).catch((err) => { }).catch((err) => {
...@@ -727,7 +727,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result ...@@ -727,7 +727,7 @@ Deletes a directory. This API uses an asynchronous callback to return the result
**Example** **Example**
```js ```js
let dirPath = pathDir + '/testDir'; let dirPath = pathDir + "/testDir";
fs.rmdir(dirPath, (err) => { fs.rmdir(dirPath, (err) => {
if (err) { if (err) {
console.info("rmdir failed with error message: " + err.message + ", error code: " + err.code); console.info("rmdir failed with error message: " + err.message + ", error code: " + err.code);
...@@ -755,7 +755,7 @@ Synchronously deletes a directory. ...@@ -755,7 +755,7 @@ Synchronously deletes a directory.
**Example** **Example**
```js ```js
let dirPath = pathDir + '/testDir'; let dirPath = pathDir + "/testDir";
fs.rmdirSync(dirPath); fs.rmdirSync(dirPath);
``` ```
...@@ -776,9 +776,9 @@ Deletes a file. This API uses a promise to return the result. ...@@ -776,9 +776,9 @@ Deletes a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -853,17 +853,17 @@ Writes data into a file. This API uses a promise to return the result. ...@@ -853,17 +853,17 @@ Writes data into a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.| | Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example** **Example**
...@@ -889,12 +889,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re ...@@ -889,12 +889,12 @@ Writes data into a file. This API uses an asynchronous callback to return the re
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ---------------------------------------- | | -------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Example** **Example**
...@@ -922,17 +922,17 @@ Synchronously writes data into a file. ...@@ -922,17 +922,17 @@ Synchronously writes data into a file.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data written in the file.| | number | Length of the data written in the file.|
**Example** **Example**
...@@ -961,9 +961,9 @@ Truncates a file. This API uses a promise to return the result. ...@@ -961,9 +961,9 @@ Truncates a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1050,9 +1050,9 @@ Reads the text content of a file. This API uses a promise to return the result. ...@@ -1050,9 +1050,9 @@ Reads the text content of a file. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the content read.| | Promise&lt;string&gt; | Promise used to return the content read.|
**Example** **Example**
...@@ -1113,9 +1113,9 @@ Synchronously reads the text of a file. ...@@ -1113,9 +1113,9 @@ Synchronously reads the text of a file.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------------------- | | ------ | -------------------- |
| string | Promise used to return the content of the file read.| | string | Promise used to return the content of the file read.|
**Example** **Example**
...@@ -1141,9 +1141,9 @@ Obtains information about a symbolic link. This API uses a promise to return the ...@@ -1141,9 +1141,9 @@ Obtains information about a symbolic link. This API uses a promise to return the
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------- | ---------- | | ---------------------------- | ---------- |
| Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.| | Promise&lt;[Stat](#stat)&gt; | Promise used to return the symbolic link information obtained. For details, see **stat**.|
**Example** **Example**
...@@ -1201,9 +1201,9 @@ Obtains information about a symbolic link synchronously. ...@@ -1201,9 +1201,9 @@ Obtains information about a symbolic link synchronously.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------- | ---------- | | ------------- | ---------- |
| [Stat](#stat) | File information obtained.| | [Stat](#stat) | File information obtained.|
**Example** **Example**
...@@ -1216,7 +1216,7 @@ Obtains information about a symbolic link synchronously. ...@@ -1216,7 +1216,7 @@ Obtains information about a symbolic link synchronously.
rename(oldPath: string, newPath: string): Promise&lt;void&gt; rename(oldPath: string, newPath: string): Promise&lt;void&gt;
Renames a file or directory. This API uses a promise to return the result. Renames a file or folder. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1229,15 +1229,15 @@ Renames a file or directory. This API uses a promise to return the result. ...@@ -1229,15 +1229,15 @@ Renames a file or directory. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let srcFile = pathDir + "/test.txt"; let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/new.txt'; let dstFile = pathDir + "/new.txt";
fs.rename(srcFile, dstFile).then(() => { fs.rename(srcFile, dstFile).then(() => {
console.info("File renamed"); console.info("File renamed");
}).catch((err) => { }).catch((err) => {
...@@ -1249,7 +1249,7 @@ Renames a file or directory. This API uses a promise to return the result. ...@@ -1249,7 +1249,7 @@ Renames a file or directory. This API uses a promise to return the result.
rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void rename(oldPath: string, newPath: string, callback: AsyncCallback&lt;void&gt;): void
Renames a file or directory. This API uses an asynchronous callback to return the result. Renames a file or folder. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1265,7 +1265,7 @@ Renames a file or directory. This API uses an asynchronous callback to return th ...@@ -1265,7 +1265,7 @@ Renames a file or directory. This API uses an asynchronous callback to return th
```js ```js
let srcFile = pathDir + "/test.txt"; let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/new.txt'; let dstFile = pathDir + "/new.txt";
fs.rename(srcFile, dstFile, (err) => { fs.rename(srcFile, dstFile, (err) => {
if (err) { if (err) {
console.info("rename failed with error message: " + err.message + ", error code: " + err.code); console.info("rename failed with error message: " + err.message + ", error code: " + err.code);
...@@ -1279,7 +1279,7 @@ Renames a file or directory. This API uses an asynchronous callback to return th ...@@ -1279,7 +1279,7 @@ Renames a file or directory. This API uses an asynchronous callback to return th
renameSync(oldPath: string, newPath: string): void renameSync(oldPath: string, newPath: string): void
Renames a file or directory synchronously. Renames a file or folder synchronously.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
...@@ -1294,7 +1294,7 @@ Renames a file or directory synchronously. ...@@ -1294,7 +1294,7 @@ Renames a file or directory synchronously.
```js ```js
let srcFile = pathDir + "/test.txt"; let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/new.txt'; let dstFile = pathDir + "/new.txt";
fs.renameSync(srcFile, dstFile); fs.renameSync(srcFile, dstFile);
``` ```
...@@ -1309,15 +1309,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. ...@@ -1309,15 +1309,15 @@ Flushes data of a file to disk. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.| | fd | number | Yes | FD of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1342,10 +1342,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1342,10 +1342,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | --------------- | | -------- | ------------------------- | ---- | --------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| | Callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Example** **Example**
...@@ -1373,9 +1373,9 @@ Flushes data of a file to disk synchronously. ...@@ -1373,9 +1373,9 @@ Flushes data of a file to disk synchronously.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.| | fd | number | Yes | FD of the file.|
**Example** **Example**
...@@ -1397,15 +1397,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. ** ...@@ -1397,15 +1397,15 @@ Flushes data of a file to disk. This API uses a promise to return the result. **
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.| | fd | number | Yes | FD of the file.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -1431,10 +1431,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return ...@@ -1431,10 +1431,10 @@ Flushes data of a file to disk. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------------- | ---- | ----------------- | | -------- | ------------------------------- | ---- | ----------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file data is synchronized in asynchronous mode.|
**Example** **Example**
...@@ -1461,9 +1461,9 @@ Synchronizes data in a file synchronously. ...@@ -1461,9 +1461,9 @@ Synchronizes data in a file synchronously.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------------ | | ---- | ------ | ---- | ------------ |
| fd | number | Yes | FD of the file.| | fd | number | Yes | FD of the file.|
**Example** **Example**
...@@ -1492,15 +1492,15 @@ Creates a symbolic link based on a file path. This API uses a promise to return ...@@ -1492,15 +1492,15 @@ Creates a symbolic link based on a file path. This API uses a promise to return
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ---------------------------- | | ------------------- | ---------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let srcFile = pathDir + "/test.txt"; let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/test'; let dstFile = pathDir + "/test";
fs.symlink(srcFile, dstFile).then(() => { fs.symlink(srcFile, dstFile).then(() => {
console.info("Symbolic link created"); console.info("Symbolic link created");
}).catch((err) => { }).catch((err) => {
...@@ -1528,7 +1528,7 @@ Creates a symbolic link based on a file path. This API uses an asynchronous call ...@@ -1528,7 +1528,7 @@ Creates a symbolic link based on a file path. This API uses an asynchronous call
```js ```js
let srcFile = pathDir + "/test.txt"; let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/test'; let dstFile = pathDir + "/test";
fs.symlink(srcFile, dstFile, (err) => { fs.symlink(srcFile, dstFile, (err) => {
if (err) { if (err) {
console.info("symlink failed with error message: " + err.message + ", error code: " + err.code); console.info("symlink failed with error message: " + err.message + ", error code: " + err.code);
...@@ -1557,7 +1557,7 @@ Synchronously creates a symbolic link based on a file path. ...@@ -1557,7 +1557,7 @@ Synchronously creates a symbolic link based on a file path.
```js ```js
let srcFile = pathDir + "/test.txt"; let srcFile = pathDir + "/test.txt";
let dstFile = pathDir + '/test'; let dstFile = pathDir + "/test";
fs.symlinkSync(srcFile, dstFile); fs.symlinkSync(srcFile, dstFile);
``` ```
...@@ -1568,30 +1568,30 @@ listFile(path: string, options?: { ...@@ -1568,30 +1568,30 @@ listFile(path: string, options?: {
filter?: Filter; filter?: Filter;
}): Promise<string[]>; }): Promise<string[]>;
Lists all files in a directory. This API uses a promise to return the result.<br>This API supports recursive listing of all files (including files in subdirectories) and file filtering. Lists all files in a folder. This API uses a promise to return the result.<br>This API supports recursive listing of all files (including files in subfolders) and file filtering.
**System capability**: SystemCapability.FileManagement.File.FileIO **System capability**: SystemCapability.FileManagement.File.FileIO
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.| | path | string | Yes | Path of the folder in the application sandbox.|
| options | Object | No | File filtering options.| | options | Object | No | File filtering options.|
**options parameters** **options parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| | recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.| | listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| | filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string[]&gt; | Promise used to return the files names listed.| | Promise&lt;string[]&gt; | Promise used to return the files names listed.|
**Example** **Example**
...@@ -1608,7 +1608,7 @@ Lists all files in a directory. This API uses a promise to return the result.<br ...@@ -1608,7 +1608,7 @@ Lists all files in a directory. This API uses a promise to return the result.<br
}; };
fs.listFile(pathDir, options).then((filenames) => { fs.listFile(pathDir, options).then((filenames) => {
console.info("listFile succeed"); console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) { for (let i = 0; i < filenames.length; i++) {
console.info("fileName: %s", filenames[i]); console.info("fileName: %s", filenames[i]);
} }
}).catch((err) => { }).catch((err) => {
...@@ -1623,23 +1623,23 @@ listFile(path: string, options?: { ...@@ -1623,23 +1623,23 @@ listFile(path: string, options?: {
filter?: Filter; filter?: Filter;
}, callback: AsyncCallback<string[]>): void; }, callback: AsyncCallback<string[]>): void;
Lists all files in a directory. This API uses an asynchronous callback to return the result.<br>This API supports recursive listing of all files (including files in subdirectories) and file filtering. Lists all files in a folder. This API uses an asynchronous callback to return the result.<br>This API supports recursive listing of all files (including files in subfolders) and file filtering.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.| | path | string | Yes | Path of the folder in the application sandbox.|
| options | Object | No | File filtering options.| | options | Object | No | File filtering options.|
| callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. | | callback | AsyncCallback&lt;string[]&gt; | Yes | Callback invoked to return the file names listed. |
**options parameters** **options parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| | recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.| | listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| | filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Example** **Example**
...@@ -1659,7 +1659,7 @@ Lists all files in a directory. This API uses an asynchronous callback to return ...@@ -1659,7 +1659,7 @@ Lists all files in a directory. This API uses an asynchronous callback to return
console.info("list file failed with error message: " + err.message + ", error code: " + err.code); console.info("list file failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
console.info("listFile succeed"); console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) { for (let i = 0; i < filenames.length; i++) {
console.info("filename: %s", filenames[i]); console.info("filename: %s", filenames[i]);
} }
} }
...@@ -1674,28 +1674,28 @@ listFileSync(path: string, options?: { ...@@ -1674,28 +1674,28 @@ listFileSync(path: string, options?: {
filter?: Filter; filter?: Filter;
}): string[]; }): string[];
Lists all files in a directory synchronously. This API supports recursive listing of all files (including files in subdirectories) and file filtering. Lists all files in a folder synchronously. This API supports recursive listing of all files (including files in subfolders) and file filtering.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| path | string | Yes | Path of the directory in the application sandbox.| | path | string | Yes | Path of the folder in the application sandbox.|
| options | Object | No | File filtering options.| | options | Object | No | File filtering options.|
**options parameters** **options parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| recursion | boolean | No | Whether to list all files in subdirectories recursively. The default value is **false**.| | recursion | boolean | No | Whether to list all files in subfolders recursively. The default value is **false**.|
| listNum | number | No | Number of file names to list. The default value **0** means to list all files.| | listNum | number | No | Number of file names to list. The default value **0** means to list all files.|
| filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.| | filter | [Filter](#filter) | No | File filtering options. Currently, only the match by file name extension, fuzzy search by file name, and filter by file size or latest modification time are supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| string[] | File names listed.| | string[] | File names listed.|
**Example** **Example**
...@@ -1712,13 +1712,13 @@ Lists all files in a directory synchronously. This API supports recursive listin ...@@ -1712,13 +1712,13 @@ Lists all files in a directory synchronously. This API supports recursive listin
}; };
let filenames = fs.listFileSync(pathDir, options); let filenames = fs.listFileSync(pathDir, options);
console.info("listFile succeed"); console.info("listFile succeed");
for (let i = 0; i < filenames.size; i++) { for (let i = 0; i < filenames.length; i++) {
console.info("filename: %s", filenames[i]); console.info("filename: %s", filenames[i]);
} }
``` ```
## fs.moveFile ## fs.moveFile
moveFile(src: string, dest: string, mode?: number): Promise<void>; moveFile(src: string, dest: string, mode?: number): Promise\<void>;
Moves a file. This API uses a promise to return the result. Moves a file. This API uses a promise to return the result.
...@@ -1726,15 +1726,17 @@ Moves a file. This API uses a promise to return the result. ...@@ -1726,15 +1726,17 @@ Moves a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.| | src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.| | dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example** **Example**
```js ```js
let srcPath = pathDir + "/source.txt";
let destPath = pathDir + "/dest.txt";
fs.moveFile(srcPath, destPath, 0).then(() => { fs.moveFile(srcPath, destPath, 0).then(() => {
console.info("move file succeed"); console.info("move file succeed");
}).catch((err) => { }).catch((err) => {
...@@ -1744,7 +1746,7 @@ Moves a file. This API uses a promise to return the result. ...@@ -1744,7 +1746,7 @@ Moves a file. This API uses a promise to return the result.
## fs.moveFile ## fs.moveFile
moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback<void>): void; moveFile(src: string, dest: string, mode?: number, callback: AsyncCallback\<void>): void;
Moves a file. This API uses an asynchronous callback to return the result. Moves a file. This API uses an asynchronous callback to return the result.
...@@ -1752,16 +1754,18 @@ Moves a file. This API uses an asynchronous callback to return the result. ...@@ -1752,16 +1754,18 @@ Moves a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.| | src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.| | dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is moved. |
**Example** **Example**
```js ```js
let srcPath = pathDir + "/source.txt";
let destPath = pathDir + "/dest.txt";
fs.moveFile(srcPath, destPath, 0, (err) => { fs.moveFile(srcPath, destPath, 0, (err) => {
if (err) { if (err) {
console.info("move file failed with error message: " + err.message + ", error code: " + err.code); console.info("move file failed with error message: " + err.message + ", error code: " + err.code);
...@@ -1781,15 +1785,17 @@ Moves a file synchronously. ...@@ -1781,15 +1785,17 @@ Moves a file synchronously.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| src | string | Yes | Path of the file to move in the application sandbox.| | src | string | Yes | Path of the file to move in the application sandbox.|
| dest | string | Yes | Destination path of the file in the application sandbox.| | dest | string | Yes | Destination path of the file in the application sandbox.|
| mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.| | mode | number | No | Whether to overwrite the file of the same name in the destination directory. The value **0** means to overwrite the file of the same name in the destination directory. The value **1** means to throw an exception if a file of the same name exists in the destination directory. The default value is **0**.|
**Example** **Example**
```js ```js
let srcPath = pathDir + "/source.txt";
let destPath = pathDir + "/dest.txt";
fs.moveFileSync(srcPath, destPath, 0); fs.moveFileSync(srcPath, destPath, 0);
console.info("move file succeed"); console.info("move file succeed");
``` ```
...@@ -1804,15 +1810,15 @@ Creates a temporary directory. This API uses a promise to return the result. ...@@ -1804,15 +1810,15 @@ Creates a temporary directory. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ---------- | | --------------------- | ---------- |
| Promise&lt;string&gt; | Promise used to return the unique directory generated.| | Promise&lt;string&gt; | Promise used to return the unique directory generated.|
**Example** **Example**
...@@ -1835,10 +1841,10 @@ Creates a temporary directory. This API uses an asynchronous callback to return ...@@ -1835,10 +1841,10 @@ Creates a temporary directory. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | --------------------------- | | -------- | --------------------------- | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. | | callback | AsyncCallback&lt;string&gt; | Yes | Callback invoked when a temporary directory is created asynchronously. |
**Example** **Example**
...@@ -1862,21 +1868,21 @@ Synchronously creates a temporary directory. ...@@ -1862,21 +1868,21 @@ Synchronously creates a temporary directory.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------ | ------ | ---- | --------------------------- | | ------ | ------ | ---- | --------------------------- |
| prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.| | prefix | string | Yes | A randomly generated string used to replace "XXXXXX" in a directory.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | ---------- | | ------ | ---------- |
| string | Unique path generated.| | string | Unique path generated.|
**Example** **Example**
```js ```js
let res = fs.mkdtempSync(pathDir + "/XXXXXX"); let res = fs.mkdtempSync(pathDir + "/XXXXXX");
``` ```
## fs.createStream ## fs.createStream
...@@ -1895,9 +1901,9 @@ Opens a file stream based on the file path. This API uses a promise to return th ...@@ -1895,9 +1901,9 @@ Opens a file stream based on the file path. This API uses a promise to return th
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -1957,9 +1963,9 @@ Synchronously opens a stream based on the file path. ...@@ -1957,9 +1963,9 @@ Synchronously opens a stream based on the file path.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream) | Stream opened.| | [Stream](#stream) | Stream opened.|
**Example** **Example**
...@@ -1979,16 +1985,16 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret ...@@ -1979,16 +1985,16 @@ Opens a file stream based on the file descriptor. This API uses a promise to ret
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------------------- | --------- | | --------------------------------- | --------- |
| Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.| | Promise&lt;[Stream](#stream)&gt; | Promise used to return the result.|
**Example** **Example**
...@@ -2014,11 +2020,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous ...@@ -2014,11 +2020,11 @@ Opens a file stream based on the file descriptor. This API uses an asynchronous
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
| callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. | | callback | AsyncCallback&lt;[Stream](#stream)&gt; | Yes | Callback invoked when the stream is open asynchronously. |
**Example** **Example**
...@@ -2045,16 +2051,16 @@ Synchronously opens a stream based on the file descriptor. ...@@ -2045,16 +2051,16 @@ Synchronously opens a stream based on the file descriptor.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| fd | number | Yes | FD of the file. | | fd | number | Yes | FD of the file. |
| mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).| | mode | string | Yes | - **r**: Open a file for reading. The file must exist.<br>- **r+**: Open a file for both reading and writing. The file must exist.<br>- **w**: Open a file for writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **w+**: Open a file for both reading and writing. If the file exists, clear its content. If the file does not exist, create a file.<br>- **a**: Open a file in append mode for writing at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).<br>- **a+**: Open a file in append mode for reading or updating at the end of the file. If the file does not exist, create a file. If the file exists, write data to the end of the file (the original content of the file is reserved).|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Stream](#stream) | Stream opened.| | [Stream](#stream) | Stream opened.|
**Example** **Example**
...@@ -2077,17 +2083,17 @@ Creates a **Watcher** object to observe file or directory changes. ...@@ -2077,17 +2083,17 @@ Creates a **Watcher** object to observe file or directory changes.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| path | string | Yes | Path of the file or directory to observe in the application sandbox. | | path | string | Yes | Path of the file or directory to observe in the application sandbox. |
| events | number | Yes | Events to observe. Multiple events can be separated|by a bitwise OR operator (&#124;).<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted form the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **0xfff: IN_ALL_EVENTS**: All events.| | events | number | Yes | Events to observe. Multiple events can be separated by a bitwise OR operator (&#124;).<br>- **0x1: IN_ACCESS**: A file is accessed.<br>- **0x2: IN_MODIFY**: The file content is modified.<br>- **0x4: IN_ATTRIB**: Metadata is changed.<br>- **0x8: IN_CLOSE_WRITE**: The file opened for writing is closed.<br>- **0x10: IN_CLOSE_NOWRITE**: The file or directory not opened for writing is closed.<br>- **0x20: IN_OPEN**: A file or directory is opened.<br>- **0x40: IN_MOVED_FROM**: A file in the observed directory is moved.<br>- **0x80: IN_MOVED_TO**: A file is moved to the observed directory.<br>- **0x100: IN_CREATE**: A file or directory is created in the observed directory.<br>- **0x200: IN_DELETE**: A file or directory is deleted form the observed directory.<br>- **0x400: IN_DELETE_SELF**: The observed directory is deleted. After the directory is deleted, the listening stops.<br>- **0x800: IN_MOVE_SELF**: The observed file or directory is moved. After the file or directory is moved, the listening continues.<br>- **0xfff: IN_ALL_EVENTS**: All events.|
| listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. | | listener | WatchEventListener | Yes | Callback invoked when an observed event occurs. The callback will be invoked each time an observed event occurs. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------ | --------- | | ------------------ | --------- |
| [Watcher](#watcher10) | **Watcher** object created.| | [Watcher](#watcher10) | **Watcher** object created.|
**Example** **Example**
...@@ -2119,10 +2125,10 @@ Called when an observed event occurs. ...@@ -2119,10 +2125,10 @@ Called when an observed event occurs.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- | | ---- | ------ | ---- | ---------------------------------------- |
| event | WatchEvent | Yes | Event for the callback to invoke. | | event | WatchEvent | Yes | Event for the callback to invoke. |
## WatchEvent<sup>10+</sup> ## WatchEvent<sup>10+</sup>
Defines the event to observe. Defines the event to observe.
...@@ -2146,7 +2152,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c ...@@ -2146,7 +2152,7 @@ Represents detailed file information. Before calling any API of the **Stat()** c
### Attributes ### Attributes
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| ------ | ------ | ---- | ---- | ---------------------------------------- | | ------ | ------ | ---- | ---- | ---------------------------------------- |
| ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| | | ino | number | Yes | No | File ID. Different files on the same device have different **ino**s.| |
| mode | number | Yes | No | File permissions. The meaning of each bit is as follows:<br>- **0o400**: The owner has the read permission on a regular file or a directory entry.<br>- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o040**: The user group has the read permission on a regular file or a directory entry.<br>- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o004**: Other users have the permission to read a regular file or read a directory entry.<br>- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.| | mode | number | Yes | No | File permissions. The meaning of each bit is as follows:<br>- **0o400**: The owner has the read permission on a regular file or a directory entry.<br>- **0o200**: The owner has the permission to write a regular file or create and delete a directory entry.<br>- **0o100**: The owner has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o040**: The user group has the read permission on a regular file or a directory entry.<br>- **0o020**: The user group has the permission to write a regular file or create and delete a directory entry.<br>- **0o010**: The user group has the permission to execute a regular file or search for the specified path in a directory.<br>- **0o004**: Other users have the permission to read a regular file or read a directory entry.<br>- **0o002**: Other users have the permission to write a regular file or create and delete a directory entry.<br>- **0o001**: Other users have the permission to execute a regular file or search for the specified path in a directory.|
| uid | number | Yes | No | ID of the file owner.| | uid | number | Yes | No | ID of the file owner.|
...@@ -2167,9 +2173,9 @@ Checks whether this file is a block special file. A block special file supports ...@@ -2167,9 +2173,9 @@ Checks whether this file is a block special file. A block special file supports
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ---------------- | | ------- | ---------------- |
| boolean | Whether the file is a block special file.| | boolean | Whether the file is a block special file.|
**Example** **Example**
...@@ -2188,9 +2194,9 @@ Checks whether this file is a character special file. A character special file s ...@@ -2188,9 +2194,9 @@ Checks whether this file is a character special file. A character special file s
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ----------------- | | ------- | ----------------- |
| boolean | Whether the file is a character special file.| | boolean | Whether the file is a character special file.|
**Example** **Example**
...@@ -2210,9 +2216,9 @@ Checks whether this file is a directory. ...@@ -2210,9 +2216,9 @@ Checks whether this file is a directory.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------- | | ------- | ------------- |
| boolean | Whether the file is a directory.| | boolean | Whether the file is a directory.|
**Example** **Example**
...@@ -2232,9 +2238,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int ...@@ -2232,9 +2238,9 @@ Checks whether this file is a named pipe (or FIFO). Named pipes are used for int
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------------- | | ------- | --------------------- |
| boolean | Whether the file is a FIFO.| | boolean | Whether the file is a FIFO.|
**Example** **Example**
...@@ -2254,9 +2260,9 @@ Checks whether this file is a regular file. ...@@ -2254,9 +2260,9 @@ Checks whether this file is a regular file.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the file is a regular file.| | boolean | Whether the file is a regular file.|
**Example** **Example**
...@@ -2276,9 +2282,9 @@ Checks whether this file is a socket. ...@@ -2276,9 +2282,9 @@ Checks whether this file is a socket.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------- | | ------- | -------------- |
| boolean | Whether the file is a socket.| | boolean | Whether the file is a socket.|
**Example** **Example**
...@@ -2298,9 +2304,9 @@ Checks whether this file is a symbolic link. ...@@ -2298,9 +2304,9 @@ Checks whether this file is a symbolic link.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------- | | ------- | --------------- |
| boolean | Whether the file is a symbolic link.| | boolean | Whether the file is a symbolic link.|
**Example** **Example**
...@@ -2324,9 +2330,9 @@ Closes the stream. This API uses a promise to return the result. ...@@ -2324,9 +2330,9 @@ Closes the stream. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream close result.| | Promise&lt;void&gt; | Promise used to return the stream close result.|
**Example** **Example**
...@@ -2351,9 +2357,9 @@ Closes the stream. This API uses an asynchronous callback to return the result. ...@@ -2351,9 +2357,9 @@ Closes the stream. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ------------- | | -------- | ------------------------- | ---- | ------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is closed asynchronously.|
**Example** **Example**
...@@ -2395,9 +2401,9 @@ Flushes the stream. This API uses a promise to return the result. ...@@ -2395,9 +2401,9 @@ Flushes the stream. This API uses a promise to return the result.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------- | | ------------------- | ------------- |
| Promise&lt;void&gt; | Promise used to return the stream flushing result.| | Promise&lt;void&gt; | Promise used to return the stream flushing result.|
**Example** **Example**
...@@ -2422,9 +2428,9 @@ Flushes the stream. This API uses an asynchronous callback to return the result. ...@@ -2422,9 +2428,9 @@ Flushes the stream. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | -------------- | | -------- | ------------------------- | ---- | -------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the stream is asynchronously flushed.|
**Example** **Example**
...@@ -2466,16 +2472,16 @@ Writes data into the stream. This API uses a promise to return the result. ...@@ -2466,16 +2472,16 @@ Writes data into the stream. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | -------- | | --------------------- | -------- |
| Promise&lt;number&gt; | Promise used to return the length of the data written.| | Promise&lt;number&gt; | Promise used to return the length of the data written.|
**Example** **Example**
...@@ -2500,11 +2506,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th ...@@ -2500,11 +2506,11 @@ Writes data into the stream. This API uses an asynchronous callback to return th
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------------- | ---- | ------------------------------------------------------------ |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when the data is written asynchronously. |
**Example** **Example**
...@@ -2532,16 +2538,16 @@ Synchronously writes data into the stream. ...@@ -2532,16 +2538,16 @@ Synchronously writes data into the stream.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ------------------------------- | ---- | ---------------------------------------- | | ------- | ------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. | | buffer | ArrayBuffer\|string | Yes | Data to write. It can be a string or data from a buffer. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to write. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): start position to write the data in the file. This parameter is optional. By default, data is written from the current position.<br>- **encoding** (string): format of the data to be encoded when the data is a string. The default value is **'utf-8'**, which is the only value supported.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data written in the file.| | number | Length of the data written in the file.|
**Example** **Example**
...@@ -2561,16 +2567,16 @@ Reads data from the stream. This API uses a promise to return the result. ...@@ -2561,16 +2567,16 @@ Reads data from the stream. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. By default, data is read from the current position.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;number&gt; | Promise used to return the data read.| | Promise&lt;number&gt; | Promise used to return the data read.|
**Example** **Example**
...@@ -2580,7 +2586,7 @@ Reads data from the stream. This API uses a promise to return the result. ...@@ -2580,7 +2586,7 @@ Reads data from the stream. This API uses a promise to return the result.
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
ss.read(buf, {offset: 5, length: 5}).then((readLen) => { ss.read(buf, {offset: 5, length: 5}).then((readLen) => {
console.info("Read data successfully"); console.info("Read data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(buf))); console.log(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
}).catch((err) => { }).catch((err) => {
console.info("read data failed with error message: " + err.message + ", error code: " + err.code); console.info("read data failed with error message: " + err.message + ", error code: " + err.code);
}); });
...@@ -2597,11 +2603,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the ...@@ -2597,11 +2603,11 @@ Reads data from the stream. This API uses an asynchronous callback to return the
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | ---------------------------------------- | ---- | ---------------------------------------- | | -------- | ---------------------------------------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.| | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when data is read asynchronously from the stream. | | callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked when data is read asynchronously from the stream. |
**Example** **Example**
...@@ -2614,7 +2620,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the ...@@ -2614,7 +2620,7 @@ Reads data from the stream. This API uses an asynchronous callback to return the
console.info("read stream failed with error message: " + err.message + ", error code: " + err.code); console.info("read stream failed with error message: " + err.message + ", error code: " + err.code);
} else { } else {
console.info("Read data successfully"); console.info("Read data successfully");
console.log(String.fromCharCode.apply(null, new Uint8Array(buf))); console.log(String.fromCharCode.apply(null, new Uint8Array(buf.slice(0, readLen))));
} }
}); });
``` ```
...@@ -2629,16 +2635,16 @@ Synchronously reads data from the stream. ...@@ -2629,16 +2635,16 @@ Synchronously reads data from the stream.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| buffer | ArrayBuffer | Yes | Buffer used to store the file read. | | buffer | ArrayBuffer | Yes | Buffer used to store the file read. |
| options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br> | | options | Object | No | The options are as follows:<br>- **length** (number): length of the data to read. This parameter is optional. The default value is the buffer length.<br>- **offset** (number): position of the data to read in the file. This parameter is optional. By default, data is read from the current position.<br> |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------ | -------- | | ------ | -------- |
| number | Length of the data read.| | number | Length of the data read.|
**Example** **Example**
...@@ -2662,7 +2668,7 @@ Represents a **File** object opened by **open()**. ...@@ -2662,7 +2668,7 @@ Represents a **File** object opened by **open()**.
### lock ### lock
lock(exclusive?: boolean): Promise<void>; lock(exclusive?: boolean): Promise\<void>;
Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result. Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
...@@ -2670,15 +2676,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A ...@@ -2670,15 +2676,15 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------------------- | ------ | | ---------------------------------- | ------ |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
...@@ -2693,7 +2699,7 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A ...@@ -2693,7 +2699,7 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
### lock ### lock
lock(exclusive?: boolean, callback: AsyncCallback<void>): void; lock(exclusive?: boolean, callback: AsyncCallback\<void>): void;
Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result. Applies an exclusive lock or a shared lock on this file in blocking mode. This API uses a promise to return the result.
...@@ -2701,10 +2707,10 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A ...@@ -2701,10 +2707,10 @@ Applies an exclusive lock or a shared lock on this file in blocking mode. This A
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is locked. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked when the file is locked. |
**Example** **Example**
...@@ -2729,9 +2735,9 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode. ...@@ -2729,9 +2735,9 @@ Applies an exclusive lock or a shared lock on this file in non-blocking mode.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | ----------- | ---- | ---------------------------------------- | | ------- | ----------- | ---- | ---------------------------------------- |
| exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. | | exclusive | boolean | No | Lock to apply. The value **true** means an exclusive lock, and the value **false** (default) means a shared lock. |
**Example** **Example**
...@@ -2760,13 +2766,13 @@ Unlocks this file synchronously. ...@@ -2760,13 +2766,13 @@ Unlocks this file synchronously.
## Watcher<sup>10+</sup> ## Watcher<sup>10+</sup>
Provides APIs for file or directory listening. Before using the APIs of **Watcher** , call **createWatcher()** to create a **Watcher** object. Provides APIs for observing the changes of files or folders. Before using the APIs of **Watcher** , call **createWatcher()** to create a **Watcher** object.
### start<sup>10+</sup> ### start<sup>10+</sup>
start(): void start(): void
Starts file or directory listening. Starts listening.
**System API**: This is a system API. **System API**: This is a system API.
...@@ -2785,7 +2791,7 @@ Starts file or directory listening. ...@@ -2785,7 +2791,7 @@ Starts file or directory listening.
stop(): void stop(): void
Stops file or directory listening. Stops listening.
**System API**: This is a system API. **System API**: This is a system API.
......
...@@ -326,9 +326,9 @@ Checks whether the specified constraint is enabled for an OS account. This API u ...@@ -326,9 +326,9 @@ Checks whether the specified constraint is enabled for an OS account. This API u
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId. | | 12300002 | invalid localId or constraint. |
| 12300003 | Account not found. | | 12300003 | the account indicated by localId dose not exist. |
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi. **Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
...@@ -376,9 +376,9 @@ Checks whether the specified constraint is enabled for an OS account. This API u ...@@ -376,9 +376,9 @@ Checks whether the specified constraint is enabled for an OS account. This API u
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId. | | 12300002 | invalid localId or constraint. |
| 12300003 | Account not found. | | 12300003 | the account indicated by localId dose not exist. |
**Example**: Check whether OS account 100 is forbidden to use Wi-Fi. **Example**: Check whether OS account 100 is forbidden to use Wi-Fi.
...@@ -475,23 +475,19 @@ checkOsAccountVerified(callback: AsyncCallback&lt;boolean&gt;): void ...@@ -475,23 +475,19 @@ checkOsAccountVerified(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether this OS account has been verified. This API uses an asynchronous callback to return the result. Checks whether this OS account has been verified. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS
**System capability**: SystemCapability.Account.OsAccount **System capability**: SystemCapability.Account.OsAccount
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------- | | -------- | ---------------------------- | ---- | ------------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. The value **true** means the OS account has been verified; the value **false** means the opposite.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If true is returned, the current account has been verified. If false is returned, the current account has not been verified.|
**Error codes** **Error codes**
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId. |
| 12300003 | Account not found. |
**Example** **Example**
...@@ -531,9 +527,9 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca ...@@ -531,9 +527,9 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId. | | 12300002 | invalid localId. |
| 12300003 | Account not found. | | 12300003 | the account indicated by localId dose not exist. |
**Example** **Example**
...@@ -555,7 +551,7 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca ...@@ -555,7 +551,7 @@ Checks whether an OS account has been verified. This API uses an asynchronous ca
### checkOsAccountVerified<sup>9+</sup> ### checkOsAccountVerified<sup>9+</sup>
checkOsAccountVerified(localId?: number): Promise&lt;boolean&gt; checkOsAccountVerified(localId: number): Promise&lt;boolean&gt;
Checks whether an OS account has been verified. This API uses a promise to return the result. Checks whether an OS account has been verified. This API uses a promise to return the result.
...@@ -567,7 +563,7 @@ Checks whether an OS account has been verified. This API uses a promise to retur ...@@ -567,7 +563,7 @@ Checks whether an OS account has been verified. This API uses a promise to retur
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------ | ---- | --------------------------------------------------------------- | | ------- | ------ | ---- | --------------------------------------------------------------- |
| localId | number | No | ID of the target OS account. If this parameter is not specified, this API checks whether the current OS account has been verified.| | localId | number | Yes | ID of the target OS account. If this parameter is not specified, this API checks whether the current OS account has been verified.|
**Return value** **Return value**
...@@ -579,9 +575,9 @@ Checks whether an OS account has been verified. This API uses a promise to retur ...@@ -579,9 +575,9 @@ Checks whether an OS account has been verified. This API uses a promise to retur
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId. | | 12300002 | invalid localId. |
| 12300003 | Account not found. | | 12300003 | the account indicated by localId dose not exist. |
**Example** **Example**
...@@ -991,7 +987,7 @@ Obtains the ID of the OS account to which the current process belongs. This API ...@@ -991,7 +987,7 @@ Obtains the ID of the OS account to which the current process belongs. This API
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
**Example** **Example**
...@@ -1028,7 +1024,7 @@ Obtains the ID of the OS account to which the current process belongs. This API ...@@ -1028,7 +1024,7 @@ Obtains the ID of the OS account to which the current process belongs. This API
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
**Example** **Example**
...@@ -1064,8 +1060,8 @@ Obtains the OS account ID based on the process UID. This API uses an asynchronou ...@@ -1064,8 +1060,8 @@ Obtains the OS account ID based on the process UID. This API uses an asynchronou
| ID| Error Message | | ID| Error Message |
| -------- | --------------- | | -------- | --------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid uid. | | 12300002 | invalid uid. |
**Example**: Obtain the ID of the OS account whose process UID is **12345678**. **Example**: Obtain the ID of the OS account whose process UID is **12345678**.
...@@ -1108,8 +1104,8 @@ Obtains the OS account ID based on the process UID. This API uses a promise to r ...@@ -1108,8 +1104,8 @@ Obtains the OS account ID based on the process UID. This API uses a promise to r
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid uid. | | 12300002 | invalid uid. |
**Example**: Obtain the ID of the OS account whose process UID is **12345678**. **Example**: Obtain the ID of the OS account whose process UID is **12345678**.
...@@ -1148,8 +1144,8 @@ Obtains the OS account ID based on the domain account information. This API uses ...@@ -1148,8 +1144,8 @@ Obtains the OS account ID based on the domain account information. This API uses
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid domainInfo. | | 12300002 | invalid domainInfo. |
**Example** **Example**
...@@ -1195,8 +1191,8 @@ Obtains the OS account ID based on the domain account information. This API uses ...@@ -1195,8 +1191,8 @@ Obtains the OS account ID based on the domain account information. This API uses
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid domainInfo. | | 12300002 | invalid domainInfo. |
**Example** **Example**
...@@ -1474,7 +1470,7 @@ Obtains information about all activated OS accounts. This API uses an asynchrono ...@@ -1474,7 +1470,7 @@ Obtains information about all activated OS accounts. This API uses an asynchrono
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
**Example** **Example**
...@@ -1511,7 +1507,7 @@ Obtains information about all activated OS accounts. This API uses a promise to ...@@ -1511,7 +1507,7 @@ Obtains information about all activated OS accounts. This API uses a promise to
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
**Example** **Example**
...@@ -2233,9 +2229,9 @@ Obtains the OS account ID based on the serial number (SN). This API uses an asyn ...@@ -2233,9 +2229,9 @@ Obtains the OS account ID based on the serial number (SN). This API uses an asyn
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid serialNumber. | | 12300002 | invalid serialNumber. |
| 12300003 | Account not found. | | 12300003 | the account indicated by serialNumber dose not exist. |
**Example**: Obtain the ID of the OS account whose SN is 12345. **Example**: Obtain the ID of the OS account whose SN is 12345.
...@@ -2276,9 +2272,9 @@ Obtains the OS account ID based on the SN. This API uses a promise to return the ...@@ -2276,9 +2272,9 @@ Obtains the OS account ID based on the SN. This API uses a promise to return the
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid serialNumber. | | 12300002 | invalid serialNumber. |
| 12300003 | Account not found. | | 12300003 | the account indicated by serialNumber dose not exist. |
**Example**: Obtain the ID of the OS account whose SN is 12345. **Example**: Obtain the ID of the OS account whose SN is 12345.
...@@ -2315,9 +2311,9 @@ Obtains the SN of an OS account based on the account ID. This API uses an asynch ...@@ -2315,9 +2311,9 @@ Obtains the SN of an OS account based on the account ID. This API uses an asynch
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId. | | 12300002 | invalid localId. |
| 12300003 | Account not found. | | 12300003 | the account indicated by localId dose not exist. |
**Example**: Obtain the SN of the OS account 100. **Example**: Obtain the SN of the OS account 100.
...@@ -2358,9 +2354,9 @@ Obtains the SN of an OS account based on the account ID. This API uses a promise ...@@ -2358,9 +2354,9 @@ Obtains the SN of an OS account based on the account ID. This API uses a promise
| ID| Error Message | | ID| Error Message |
| -------- | ------------------- | | -------- | ------------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId. | | 12300002 | invalid localId. |
| 12300003 | Account not found. | | 12300003 | the account indicated by localId dose not exist. |
**Example**: Obtain the SN of the OS account 100. **Example**: Obtain the SN of the OS account 100.
...@@ -2483,8 +2479,8 @@ Obtains the bundle ID based on the UID. This API uses an asynchronous callback t ...@@ -2483,8 +2479,8 @@ Obtains the bundle ID based on the UID. This API uses an asynchronous callback t
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid uid. | | 12300002 | invalid uid. |
**Example** **Example**
...@@ -2526,8 +2522,8 @@ Obtains the bundle ID based on the UID. This API uses a promise to return the re ...@@ -2526,8 +2522,8 @@ Obtains the bundle ID based on the UID. This API uses a promise to return the re
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid uid. | | 12300002 | invalid uid. |
**Example** **Example**
...@@ -2644,9 +2640,9 @@ Obtains the constraint source information of an OS account. This API uses an asy ...@@ -2644,9 +2640,9 @@ Obtains the constraint source information of an OS account. This API uses an asy
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId or constraint. | | 12300002 | invalid name or constraint. |
| 12300003 | Account not found. | | 12300003 | the account indicated by localId dose not exist. |
**Example** **Example**
...@@ -2691,9 +2687,9 @@ Obtains the constraint source information of an OS account. This API uses a prom ...@@ -2691,9 +2687,9 @@ Obtains the constraint source information of an OS account. This API uses a prom
| ID| Error Message | | ID| Error Message |
| -------- | ------------- | | -------- | ------------- |
| 12300001 | System service exception. | | 12300001 | system service exception. |
| 12300002 | Invalid localId or constraint. | | 12300002 | invalid name or constraint. |
| 12300003 | Account not found. | | 12300003 | the account indicated by localId dose not exist. |
**Example** **Example**
...@@ -4433,15 +4429,26 @@ Authenticates a domain account. ...@@ -4433,15 +4429,26 @@ Authenticates a domain account.
**Example** **Example**
```js ```js
let plugin = { let plugin = {
auth: (domainInfo, credential, callback) => { auth: (domainAccountInfo, credential, callback) => {
// mock authentication // mock authentication
callback.onResult(0, {}); // notify authentication result
} callback.onResult(0, {
token: new Uint8Array([0]),
remainTimes: 5,
freezingTime: 0
});
},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
} }
account_osAccount.DomainAccountManager.registerPlugin(plugin); account_osAccount.DomainAccountManager.registerPlugin(plugin);
let userAuth = new account_osAccount.UserAuth(); let userAuth = new account_osAccount.UserAuth();
let challenge = new Uint8Array([0]); let challenge = new Uint8Array([0]);
let authType = account_osAccount.AuthType.PIN; let authType = account_osAccount.AuthType.DOMAIN;
let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1; let authTrustLevel = account_osAccount.AuthTrustLevel.ATL1;
try { try {
userAuth.auth(challenge, authType, authTrustLevel, { userAuth.auth(challenge, authType, authTrustLevel, {
...@@ -4455,6 +4462,235 @@ Authenticates a domain account. ...@@ -4455,6 +4462,235 @@ Authenticates a domain account.
} }
``` ```
### authWithPopup<sup>10+</sup>
authWithPopup(domainAccountInfo: DomainAccountInfo, callback: IUserAuthCallback): void
Authenticates a domain account in a pop-up window.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {
// mock authentication
// notify authentication result
callback.onResult(0, {
token: new Uint8Array([0]),
remainTimes: 5,
freezingTime: 0
});
},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### authWithToken<sup>10+</sup>
authWithToken(domainAccountInfo: DomainAccountInfo, token: Uint8Array, callback: IUserAuthCallback): void
Authenticates a domain account by the authorization token.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| token | Uint8Array | Yes | Authorization token generated when the PIN or biometric authentication is successful.|
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {
// mock authentication
// notify authentication result
callback.onResult(0, {
token: new Uint8Array([0]),
remainTimes: 5,
freezingTime: 0
});
},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### getAccountInfo<sup>10+</sup>
getAccountInfo(domain: string, accountName: string, callback: AsyncCallback&lt;DomainAccountInfo&gt;): void
Obtains information about a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domain | string | Yes | Domain to which the account belongs.|
| accountName | string | Yes | Name of the account.|
| callback | AsyncCallback&lt;[DomainAccountInfo](#domainaccountinfo8)&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {
// mock getting account information
// notify result
callback({
code: 0
}, {
domain: domain,
accountName: accountName,
accountId: "xxxx"
})
},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### getAuthStatusInfo<sup>10+</sup>
getAuthStatusInfo(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;AuthStatusInfo&gt;): void
Obtains the authentication status of a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | AsyncCallback&lt;[AuthStatusInfo](#authstatusinfo10)&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {
callback({
code: 0
}, {
remainTimes: 5,
freezingTime: 0
})
},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### bindAccount<sup>10+</sup>
bindAccount(domainAccountInfo: DomainAccountInfo, localId: number, callback: AsyncCallback&lt;void&gt;): void
Binds a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {
// mock unbinding operation
// notify binding result
callback({code: 0})
},
unbindAccount: (domainAccountInfo, callback) => {}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
### unbindAccount<sup>10+</sup>
unbindAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;void&gt;): void
Unbinds a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result.|
**Example**
```js
let plugin = {
auth: (domainAccountInfo, credential, callback) => {},
authWithPopup: (domainAccountInfo, callback) => {},
authWithToken: (domainAccountInfo, callback) => {},
getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {
// mock unbinding operation
// notify unbinding result
callback({code: 0})
}
}
account_osAccount.DomainAccountManager.registerPlugin(plugin)
```
## DomainAccountManager <sup>9+</sup> ## DomainAccountManager <sup>9+</sup>
Provides APIs for domain account management. Provides APIs for domain account management.
...@@ -4480,15 +4716,18 @@ Registers a domain plug-in. ...@@ -4480,15 +4716,18 @@ Registers a domain plug-in.
| ID| Error Message | | ID| Error Message |
| -------- | --------------------------- | | -------- | --------------------------- |
| 12300201 | The domain plugin has been registered. | | 12300201 | the domain plugin has been registered. |
**Example** **Example**
```js ```js
let plugin = { let plugin = {
auth: (domainInfo, credential, callback) => { auth: (domainAccountInfo, credential, callback) => {},
// mock authentication authWithPopup: (domainAccountInfo, callback) => {},
callback.onResult(0, {}); authWithToken: (domainAccountInfo, callback) => {},
} getAccountInfo: (domain, accountName, callback) => {},
getAuthStatusInfo: (domainAccountInfo, callback) => {},
bindAccount: (domainAccountInfo, localId, callback) => {},
unbindAccount: (domainAccountInfo, callback) => {}
} }
try { try {
account_osAccount.DomainAccountManager.registerPlugin(plugin); account_osAccount.DomainAccountManager.registerPlugin(plugin);
...@@ -4520,6 +4759,252 @@ Unregisters this domain plug-in. ...@@ -4520,6 +4759,252 @@ Unregisters this domain plug-in.
} }
``` ```
### auth<sup>10+</sup>
auth(domainAccountInfo: DomainAccountInfo, credential: Uint8Array, callback: IUserAuthCallback): void
Authenticates a domain account.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| credential | Uint8Array | Yes | Credentials of the domain account.|
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300002 | invalid domainAccountInfo or credential. |
| 12300003 | domain account does not exist. |
| 12300013 | network exception. |
| 12300101 | authentication failed. |
| 12300109 | authentication is canceled. |
| 12300110 | authentication is locked. |
| 12300111 | authentication timeout. |
| 12300112 | authentication service is busy. |
| 12300113 | authentication service does not exist. |
| 12300114 | authentication service exception. |
**Example**
```js
let domainAccountInfo = {
domain: "CHINA",
accountName: "zhangsan"
}
let credential = new Uint8Array([0])
try {
account_osAccount.DomainAccountManager.auth(domainAccountInfo, credential, {
onResult: (resultCode, authResult) => {
console.log('auth resultCode = ' + resultCode);
console.log('auth authResult = ' + JSON.stringify(authResult));
}
});
} catch (err) {
console.log('auth exception = ' + JSON.stringify(err));
}
```
### authWithPopup<sup>10+</sup>
authWithPopup(callback: IUserAuthCallback): void
Authenticates this domain account in a pop-up window.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300003 | no domain account is bound. |
| 12300013 | network exception. |
| 12300101 | authentication failed. |
| 12300109 | authentication is canceled. |
| 12300110 | authentication is locked. |
| 12300111 | authentication timeout. |
| 12300112 | authentication service is busy. |
| 12300113 | authentication service does not exist. |
| 12300114 | authentication service exception. |
**Example**
```js
try {
account_osAccount.DomainAccountManager.authWithPopup({
onResult: (resultCode, authResult) => {
console.log('auth resultCode = ' + resultCode);
console.log('auth authResult = ' + JSON.stringify(authResult));
}
})
} catch (err) {
console.log('auth exception = ' + JSON.stringify(err));
}
```
### authWithPopup<sup>10+</sup>
authWithPopup(localId: number, callback: IUserAuthCallback): void
Authenticates a domain account in a pop-up window.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.ACCESS_USER_AUTH_INTERNAL
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| localId | number | Yes | Local ID of the OS account bound to the domain account.|
| callback | [IUserAuthCallback](#iuserauthcallback8) | Yes | Callback invoked to return the authentication result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300002 | invalid localId. |
| 12300003 | no domain account is bound. |
| 12300013 | network exception. |
| 12300101 | authentication failed. |
| 12300109 | authentication is canceled. |
| 12300110 | authentication is locked. |
| 12300111 | authentication timeout. |
| 12300112 | authentication service is busy. |
| 12300113 | authentication service does not exist. |
| 12300114 | authentication service exception. |
**Example**
```js
try {
account_osAccount.DomainAccountManager.authWithPopup(100, {
onResult: (resultCode, authResult) => {
console.log('authWithPopup resultCode = ' + resultCode);
console.log('authWithPopup authResult = ' + JSON.stringify(authResult));
}
})
} catch (err) {
console.log('authWithPopup exception = ' + JSON.stringify(err));
}
```
### hasAccount<sup>10+</sup>
hasAccount(domainAccountInfo: DomainAccountInfo, callback: AsyncCallback&lt;boolean&gt;): void
Checks whether a domain account exists.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300002 | invalid domainAccountInfo. |
| 12300013 | network exception. |
**Example**
```js
let domainAccountInfo = {
domain: "CHINA",
accountName: "zhangsan"
}
try {
account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo, (err, result) => {
if (err) {
console.log("call hasAccount failed, error: " + JSON.stringify(err));
} else {
console.log("hasAccount result: " + result);
}
});
} catch (err) {
console.log('hasAccount exception = ' + JSON.stringify(err));
}
```
### hasAccount<sup>10+</sup>
hasAccount(domainAccountInfo: DomainAccountInfo): Promise&lt;boolean&gt;
Checks whether a domain account exists.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
**Required permissions**: ohos.permission.MANAGE_LOCAL_ACCOUNTS
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | --------------------------------------- | ---- | --------------- |
| domainAccountInfo | [DomainAccountInfo](#domainaccountinfo8) | Yes | Domain account information.|
**Return value**
| Type | Description |
| :------------------------ | ----------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.|
**Error codes**
| ID| Error Message |
| -------- | --------------------------- |
| 12300001 | system service exception. |
| 12300002 | invalid domainAccountInfo. |
| 12300013 | network exception. |
**Example**
```js
let domainAccountInfo = {
domain: "CHINA",
accountName: "zhangsan"
}
try {
account_osAccount.DomainAccountManager.hasAccount(domainAccountInfo).then((result) => {
console.log("hasAccount result: " + result);
}).catch((err) => {
console.log("call hasAccount failed, error: " + JSON.stringify(err));
});
} catch (err) {
console.log('hasAccount exception = ' + JSON.stringify(err));
}
```
## UserIdentityManager<sup>8+</sup> ## UserIdentityManager<sup>8+</sup>
Provides APIs for user identity management (IDM). Provides APIs for user identity management (IDM).
...@@ -5254,7 +5739,7 @@ Defines the executor property. ...@@ -5254,7 +5739,7 @@ Defines the executor property.
| ------------ | ---------------------------------------- | ----- | ----------------- | | ------------ | ---------------------------------------- | ----- | ----------------- |
| result | number | Yes | Result. | | result | number | Yes | Result. |
| authSubType | [AuthSubType](#authsubtype8) | Yes | Authentication credential subtype.| | authSubType | [AuthSubType](#authsubtype8) | Yes | Authentication credential subtype.|
| remainTimes | number | No | Remaining time. | | remainTimes | number | No | Number of remaining authentication times. |
| freezingTime | number | No | Freezing time. | | freezingTime | number | No | Freezing time. |
## AuthResult<sup>8+</sup> ## AuthResult<sup>8+</sup>
...@@ -5268,7 +5753,7 @@ Defines the authentication result information. ...@@ -5268,7 +5753,7 @@ Defines the authentication result information.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------------ | ----------- | ----- | ----------------- | | ------------ | ----------- | ----- | ----------------- |
| token | Uint8Array | No | Authentication token. | | token | Uint8Array | No | Authentication token. |
| remainTimes | number | No | Remaining time. | | remainTimes | number | No | Number of remaining authentication times. |
| freezingTime | number | No | Freezing time. | | freezingTime | number | No | Freezing time. |
## CredentialInfo<sup>8+</sup> ## CredentialInfo<sup>8+</sup>
...@@ -5351,7 +5836,7 @@ Enumerates the authentication credential types. ...@@ -5351,7 +5836,7 @@ Enumerates the authentication credential types.
| PIN | 1 | PIN authentication.| | PIN | 1 | PIN authentication.|
| FACE | 2 | Facial authentication.| | FACE | 2 | Facial authentication.|
| FINGERPRINT<sup>10+</sup> | 4 | Fingerprint authentication.| | FINGERPRINT<sup>10+</sup> | 4 | Fingerprint authentication.|
| DOMAIN<sup>10+</sup> | 1024 | Domain authentication.| | DOMAIN<sup>9+</sup> | 1024 | Domain authentication.|
## AuthSubType<sup>8+</sup> ## AuthSubType<sup>8+</sup>
...@@ -5368,7 +5853,7 @@ Enumerates the authentication credential subtypes. ...@@ -5368,7 +5853,7 @@ Enumerates the authentication credential subtypes.
| PIN_MIXED | 10002 | Custom mixed credentials.| | PIN_MIXED | 10002 | Custom mixed credentials.|
| FACE_2D | 20000 | 2D face credential. | | FACE_2D | 20000 | 2D face credential. |
| FACE_3D | 20001 | 3D face credential. | | FACE_3D | 20001 | 3D face credential. |
| DOMAIN_MIXED<sup>10+</sup> | 10240001 | Mixed domain authentication credentials. | | DOMAIN_MIXED<sup>9+</sup> | 10240001 | Mixed domain authentication credentials. |
## AuthTrustLevel<sup>8+</sup> ## AuthTrustLevel<sup>8+</sup>
...@@ -5490,6 +5975,7 @@ Defines the domain account information. ...@@ -5490,6 +5975,7 @@ Defines the domain account information.
| ----------- | ------ | ---- | ---------- | | ----------- | ------ | ---- | ---------- |
| domain | string | Yes | Domain name. | | domain | string | Yes | Domain name. |
| accountName | string | Yes | Domain account name.| | accountName | string | Yes | Domain account name.|
| accountId<sup>10+</sup> | string | No | Domain account ID.|
## Constraints ## Constraints
...@@ -5586,3 +6072,16 @@ Enumerates the constraint sources. ...@@ -5586,3 +6072,16 @@ Enumerates the constraint sources.
| CONSTRAINT_TYPE_BASE | 1 | Constraint from system settings. | | CONSTRAINT_TYPE_BASE | 1 | Constraint from system settings. |
| CONSTRAINT_TYPE_DEVICE_OWNER | 2 | Constraint from the device owners' settings. | | CONSTRAINT_TYPE_DEVICE_OWNER | 2 | Constraint from the device owners' settings. |
| CONSTRAINT_TYPE_PROFILE_OWNER | 3 | Constraint from the profile owners' settings. | | CONSTRAINT_TYPE_PROFILE_OWNER | 3 | Constraint from the profile owners' settings. |
## AuthStatusInfo<sup>10+</sup>
Presents the authentication status information.
**System API**: This is a system API.
**System capability**: SystemCapability.Account.OsAccount
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | ---------- |
| remainTimes | number | Yes | Number of remaining authentication times. |
| freezingTime | number | Yes | Freezing time.|
因为 它太大了无法显示 source diff 。你可以改为 查看blob
...@@ -16,7 +16,7 @@ import systemcapability from '@ohos.systemCapability' ...@@ -16,7 +16,7 @@ import systemcapability from '@ohos.systemCapability'
## systemcapability.querySystemCapabilities ## systemcapability.querySystemCapabilities
querySystemCapabilities(callback: AsyncCallback<string>): void; querySystemCapabilities(callback: AsyncCallback&lt;string&gt;): void;
Queries system capabilities. This API uses an asynchronous callback to return the result. Queries system capabilities. This API uses an asynchronous callback to return the result.
...@@ -51,7 +51,7 @@ querySystemCapabilities(): Promise&lt;string&gt; ...@@ -51,7 +51,7 @@ querySystemCapabilities(): Promise&lt;string&gt;
Queries system capabilities. This API uses a promise to return the result. Queries system capabilities. This API uses a promise to return the result.
**System capability**: SystemCapability.Startup.SystemInfo **System capability**: SystemCapability.Developtools.Syscap
**Return value** **Return value**
...@@ -76,4 +76,5 @@ try { ...@@ -76,4 +76,5 @@ try {
> **NOTE** > **NOTE**
> - The system capabilities returned by the preceding APIs are in the form of an encoded numeric string. >
> The system capabilities returned by the preceding APIs are in the form of an encoded numeric string.
...@@ -127,7 +127,7 @@ Obtains the scan result. This API uses a promise to return the result. ...@@ -127,7 +127,7 @@ Obtains the scan result. This API uses a promise to return the result.
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&nbsp;&gt; | Promise used to return the detected hotspots.| | Promise&lt;&nbsp;Array&lt;[WifiScanInfo](#wifiscaninfo)&gt;&nbsp;&gt; | Promise used to return the hotspots detected.|
**Error codes** **Error codes**
...@@ -409,6 +409,8 @@ Represents EAP configuration information. ...@@ -409,6 +409,8 @@ Represents EAP configuration information.
| caCertAliases | string | Yes| No| CA certificate alias.| | caCertAliases | string | Yes| No| CA certificate alias.|
| caPath | string | Yes| No| CA certificate path.| | caPath | string | Yes| No| CA certificate path.|
| clientCertAliases | string | Yes| No| Client certificate alias.| | clientCertAliases | string | Yes| No| Client certificate alias.|
| certEntry | Uint8Array | Yes| Yes| CA certificate content.|
| certPassword | string | Yes| Yes| CA certificate password.|
| altSubjectMatch | string | Yes| No| A string to match the alternate subject.| | altSubjectMatch | string | Yes| No| A string to match the alternate subject.|
| domainSuffixMatch | string | Yes| No| A string to match the domain suffix.| | domainSuffixMatch | string | Yes| No| A string to match the domain suffix.|
| realm | string | Yes| No| Realm for the passpoint credential.| | realm | string | Yes| No| Realm for the passpoint credential.|
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
This **wifiext** module provides WLAN extension interfaces for non-universal products. This **wifiext** module provides WLAN extension interfaces for non-universal products.
> **NOTE** > **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. >
The APIs described in this document are used only for non-universal products, such as routers. > - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs described in this document are used only for non-universal products, such as routers.
## Modules to Import ## Modules to Import
...@@ -12,9 +13,9 @@ The APIs described in this document are used only for non-universal products, su ...@@ -12,9 +13,9 @@ The APIs described in this document are used only for non-universal products, su
import wifiManagerExt from '@ohos.wifiManagerExt'; import wifiManagerExt from '@ohos.wifiManagerExt';
``` ```
## wifiext.enableHotspot ## wifiext.enableHotspot<sup>9+</sup>
enableHotspot(): boolean; enableHotspot(): void;
Enables the WLAN hotspot. Enables the WLAN hotspot.
...@@ -27,12 +28,12 @@ Enables the WLAN hotspot. ...@@ -27,12 +28,12 @@ Enables the WLAN hotspot.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| 2701000 | Operation failed.| | 2701000 | Operation failed.|
## wifiext.disableHotspot ## wifiext.disableHotspot<sup>9+</sup>
disableHotspot(): boolean; disableHotspot(): void;
Disables the WLAN hotspot. Disables the WLAN hotspot.
...@@ -45,14 +46,14 @@ Disables the WLAN hotspot. ...@@ -45,14 +46,14 @@ Disables the WLAN hotspot.
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| 2701000 | Operation failed.| | 2701000 | Operation failed.|
## wifiext.getSupportedPowerModel ## wifiext.getSupportedPowerMode<sup>9+</sup>
getSupportedPowerModel(): Promise&lt;Array&lt;PowerModel&gt;&gt; getSupportedPowerMode(): Promise&lt;Array&lt;PowerMode&gt;&gt;
Obtains the supported power models. This API uses a promise to return the result. Obtains the supported power modes. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO **Required permissions**: ohos.permission.GET_WIFI_INFO
...@@ -60,21 +61,21 @@ Obtains the supported power models. This API uses a promise to return the result ...@@ -60,21 +61,21 @@ Obtains the supported power models. This API uses a promise to return the result
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Promise used to return the power models obtained.| | Promise&lt;Array&lt;[PowerMode](#powermode)&gt;&gt; | Promise used to return the power modes obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| 2701000 | Operation failed.| | 2701000 | Operation failed.|
## PowerModel ## PowerMode
Enumerates the power models. Enumerates the power modes.
**System capability**: SystemCapability.Communication.WiFi.AP.Extension **System capability**: SystemCapability.Communication.WiFi.AP.Extension
...@@ -85,11 +86,11 @@ Enumerates the power models. ...@@ -85,11 +86,11 @@ Enumerates the power models.
| THROUGH_WALL | 2 | Through_wall| | THROUGH_WALL | 2 | Through_wall|
## wifiext.getSupportedPowerModel ## wifiext.getSupportedPowerMode<sup>9+</sup>
getSupportedPowerModel(callback: AsyncCallback&lt;Array&lt;PowerModel&gt;&gt;): void getSupportedPowerMode(callback: AsyncCallback&lt;Array&lt;PowerMode&gt;&gt;): void
Obtains the supported power models. This API uses an asynchronous callback to return the result. Obtains the supported power modes. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO **Required permissions**: ohos.permission.GET_WIFI_INFO
...@@ -97,23 +98,23 @@ Obtains the supported power models. This API uses an asynchronous callback to re ...@@ -97,23 +98,23 @@ Obtains the supported power models. This API uses an asynchronous callback to re
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;Array&lt;[PowerModel](#powermodel)&gt;&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power models obtained. If **err** is not **0**, an error has occurred.| | callback | AsyncCallback&lt;Array&lt;[PowerMode](#powermode)&gt;&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power modes obtained. If **err** is not **0**, an error has occurred.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| 2701000 | Operation failed.| | 2701000 | Operation failed.|
## wifiext.getPowerModel ## wifiext.getPowerMode<sup>9+</sup>
getPowerModel(): Promise&lt;PowerModel&gt; getPowerMode(): Promise&lt;PowerMode&gt;
Obtains the power model. This API uses a promise to return the result. Obtains the power mode. This API uses a promise to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO **Required permissions**: ohos.permission.GET_WIFI_INFO
...@@ -121,23 +122,23 @@ Obtains the power model. This API uses a promise to return the result. ...@@ -121,23 +122,23 @@ Obtains the power model. This API uses a promise to return the result.
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[PowerModel](#powermodel)&gt; | Promise used to return the power models obtained.| | Promise&lt;[PowerMode](#powermode)&gt; | Promise used to return the power modes obtained.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| 2701000 | Operation failed.| | 2701000 | Operation failed.|
## wifiext.getPowerModel ## wifiext.getPowerMode<sup>9+</sup>
getPowerModel(callback: AsyncCallback&lt;PowerModel&gt;): void getPowerMode(callback: AsyncCallback&lt;PowerMode&gt;): void
Obtains the power model. This API uses an asynchronous callback to return the result. Obtains the power mode. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WIFI_INFO **Required permissions**: ohos.permission.GET_WIFI_INFO
...@@ -145,23 +146,23 @@ Obtains the power model. This API uses an asynchronous callback to return the re ...@@ -145,23 +146,23 @@ Obtains the power model. This API uses an asynchronous callback to return the re
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[PowerModel](#powermodel)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power model obtained. If **err** is not **0**, an error has occurred.| | callback | AsyncCallback&lt;[PowerMode](#powermode)&gt; | Yes| Callback invoked to return the result. If the operation is successful, **err** is **0** and **data** is the power mode obtained. If **err** is not **0**, an error has occurred.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| 2701000 | Operation failed.| | 2701000 | Operation failed.|
## wifiext.setPowerModel ## wifiext.setPowerMode<sup>9+</sup>
setPowerModel(model: PowerModel) : boolean; setPowerMode(model: PowerMode) : boolean;
Sets the power model. Sets the power mode.
**Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT **Required permissions**: ohos.permission.MANAGE_WIFI_HOTSPOT_EXT
...@@ -169,14 +170,14 @@ setPowerModel(model: PowerModel) : boolean; ...@@ -169,14 +170,14 @@ setPowerModel(model: PowerModel) : boolean;
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| model | [PowerModel](#powermodel) | Yes| Power model to set.| | model | [PowerMode](#powermode) | Yes| Power mode to set.|
**Error codes** **Error codes**
For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md). For details about the error codes, see [Wi-Fi Error Codes](../errorcodes/errorcode-wifi.md).
| **Type**| **Description**| | **Type**| **Description**|
| -------- | -------- | | -------- | -------- |
| 2701000 | Operation failed.| | 2701000 | Operation failed.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册