提交 dfcd5710 编写于 作者: J junyi233 提交者: Gitee

扫描缺陷修改

...@@ -78,9 +78,9 @@ The ability assistant is pre-installed in the device environment. You can direct ...@@ -78,9 +78,9 @@ The ability assistant is pre-installed in the device environment. You can direct
| -l/--mission-list | type (All logs are printed if this parameter is left unspecified.)| Prints mission stack information.<br>The following values are available for **type**:<br>- NORMAL <br>- DEFAULT_STANDARD<br>- DEFAULT_SINGLE<br>- LAUNCHER | | -l/--mission-list | type (All logs are printed if this parameter is left unspecified.)| Prints mission stack information.<br>The following values are available for **type**:<br>- NORMAL <br>- DEFAULT_STANDARD<br>- DEFAULT_SINGLE<br>- LAUNCHER |
| -e/--extension | elementName | Prints extended component information. | | -e/--extension | elementName | Prints extended component information. |
| -u/--userId | UserId | Prints stack information of a specified user ID. This parameter must be used together with other parameters.<br>Example commands: aa **dump -a -u 100** and **aa dump -d -u 100**| | -u/--userId | UserId | Prints stack information of a specified user ID. This parameter must be used together with other parameters.<br>Example commands: aa **dump -a -u 100** and **aa dump -d -u 100**|
| -d/--data | | Prints Data ability information. | | -d/--data | - | Prints Data ability information. |
| -i/--ability | AbilityRecord ID | Prints detailed information about a specified ability. | | -i/--ability | AbilityRecord ID | Prints detailed information about a specified ability. |
| -c/--client | | Prints detailed ability information. This parameter must be used together with other parameters.<br>Example commands: **aa dump -a -c** and **aa dump -i 21 -c**| | -c/--client | - | Prints detailed ability information. This parameter must be used together with other parameters.<br>Example commands: **aa dump -a -c** and **aa dump -i 21 -c**|
**Method** **Method**
......
...@@ -132,7 +132,9 @@ You can also include **parameters** in the **want** parameter and set its value ...@@ -132,7 +132,9 @@ You can also include **parameters** in the **want** parameter and set its value
); );
``` ```
### Starting a Remote Page Ability ### Starting a Remote Page Ability
>Note: This feature applies only to system applications, since the **getTrustedDeviceListSync** API of the **DeviceManager** class is open only to system applications. >Note
>
>This feature applies only to system applications, since the **getTrustedDeviceListSync** API of the **DeviceManager** class is open only to system applications.
**Modules to Import** **Modules to Import**
......
...@@ -166,7 +166,7 @@ let connId = featureAbility.connectAbility( ...@@ -166,7 +166,7 @@ let connId = featureAbility.connectAbility(
); );
``` ```
When a Service ability is connected, the **onConnect()** callback is invoked and returns an **IRemoteObject** defining the proxy used for communicating with the Service ability. OpenHarmony provides a default implementation of the **IRemoteObject** interface. You can extend **rpc.RemoteObject** to implement your own class of **IRemoteObject**. When a Service ability is connected, the **onConnect()** callback is invoked and returns an **IRemoteObject** defining the proxy used for communicating with the Service ability. OpenHarmony provides a default implementation of **IRemoteObject**. You can extend **rpc.RemoteObject** to implement your own class of **IRemoteObject**.
The following code snippet shows how the Service ability instance returns itself to the calling ability: The following code snippet shows how the Service ability instance returns itself to the calling ability:
......
...@@ -119,7 +119,7 @@ The following table lists the APIs used for ability continuation. For details ab ...@@ -119,7 +119,7 @@ The following table lists the APIs used for ability continuation. For details ab
```javascript ```javascript
onContinue(wantParam : {[key: string]: any}) { onContinue(wantParam : {[key: string]: any}) {
Logger.info("onContinue using distributedObject") Logger.info("onContinue using distributedObject")
// Set the user input data into the want parameter. // Set the user input data into want params.
wantParam["input"] = AppStorage.Get<string>('ContinueInput'); wantParam["input"] = AppStorage.Get<string>('ContinueInput');
Logger.info(`onContinue input = ${wantParam["input"]}`); Logger.info(`onContinue input = ${wantParam["input"]}`);
return AbilityConstant.OnContinueResult.AGREE return AbilityConstant.OnContinueResult.AGREE
......
...@@ -12,7 +12,8 @@ Basic concepts: ...@@ -12,7 +12,8 @@ Basic concepts:
- Widget host: an application that displays the widget content and controls the position where the widget is displayed in the host application. - Widget host: an application that displays the widget content and controls the position where the widget is displayed in the host application.
- Widget Manager: a resident agent that manages widgets added to the system and provides functions such as periodic widget update. - Widget Manager: a resident agent that manages widgets added to the system and provides functions such as periodic widget update.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> The widget host and provider do not keep running all the time. The Widget Manager starts the widget provider to obtain widget information when a widget is added, deleted, or updated. > The widget host and provider do not keep running all the time. The Widget Manager starts the widget provider to obtain widget information when a widget is added, deleted, or updated.
You only need to develop widget content as the widget provider. The system automatically handles the work done by the widget host and Widget Manager. You only need to develop widget content as the widget provider. The system automatically handles the work done by the widget host and Widget Manager.
...@@ -254,7 +255,7 @@ Data of a temporary widget is not persistently stored. If it is deleted from the ...@@ -254,7 +255,7 @@ Data of a temporary widget is not persistently stored. If it is deleted from the
### Updating Widget Data ### Updating Widget Data
When a widget application initiates a data update upon a scheduled or periodic update, the application obtains the latest data and calls **updateForm** to update the widget. The code snippet is as follows: When a widget application initiates a data update upon a scheduled or periodic update, the application obtains the latest data and calls **updateForm** to update the widget. The sample code is as follows:
```javascript ```javascript
onUpdate(formId) { onUpdate(formId) {
......
# Service Extension Ability Development # Service Extension Ability Development
## When to Use ## When to Use
**ExtensionAbility** is the base class of the new Extension component in the stage model. It is used to process missions without UIs. The lifecycle of an Extension ability is simple and does not involve foreground or background. **ServiceExtensionAbility** is extended from **ExtensionAbility**. **ExtensionAbility** is the base class of the new Extension component in the stage model. It is used to process missions without UIs. The lifecycle of an Extension ability is simple and does not involve foreground or background states. **ServiceExtensionAbility** is extended from **ExtensionAbility**.
You can customize a class that inherits from **ServiceExtensionAbility** and override the lifecycle callbacks in the base class to perform service logic operations during the initialization, connection, and disconnection processes. You can customize a class that inherits from **ServiceExtensionAbility** and override the lifecycle callbacks in the base class to perform service logic operations during the initialization, connection, and disconnection processes.
## Available APIs ## Available APIs
**Table 1** ServiceExtensionAbility lifecycle callbacks **Table 1** ServiceExtensionAbility lifecycle APIs
|API|Description| |API|Description|
|:------|:------| |:------|:------|
|onCreate|Called for the initialization when **startAbility** or **connectAbility** is invoked for a given ability for the first time.| |onCreate(want: Want): void|Called for the initialization when **startAbility** or **connectAbility** is invoked for a given ability for the first time.|
|onRequest|Called each time **startAbility** is invoked for a given ability. The initial value of **startId** is 1, and the value is incremented by one each time **startAbility** is invoked for that ability.| |onRequest(want: Want, startId: number): void|Called each time **startAbility** is invoked for a given ability. The initial value of **startId** is **1**, and the value is incremented by one each time **startAbility** is invoked for that ability.|
|onConnect|Called when **connectAbility** is invoked for a given ability. This callback is not invoked for repeated calling of **connectAbility** for a specific ability. However, it will be invoked when **disconnectAbility** is called to disconnect an ability and then **connectAbility** is called to connect the ability again. The returned result is a **RemoteObject**.| |onConnect(want: Want): rpc.RemoteObject|Called when **connectAbility** is invoked for a given ability. This callback is not invoked for repeated calling of **connectAbility** for a specific ability. However, it will be invoked unless **connectAbility** is called after the ability has been disconnected using **disconnectAbility**. The returned result is a **RemoteObject**.|
|onDisconnect|Called when **disconnectAbility** is called for a given ability. If the Extension ability is started by **connectAbility** and is not bound by other applications, the **onDestroy** callback will also be triggered to destroy the Extension ability.| |onDisconnect(want: Want): void|Called when **disconnectAbility** is called for a given ability. If the Extension ability is started by **connectAbility** and is not bound to other applications, the **onDestroy** callback will also be triggered to destroy the Extension ability.|
|onDestroy|Called when **terminateSelf** is invoked to terminate the ability.| |onDestroy(): void|Called when **terminateSelf** is invoked to terminate the ability.|
## Constraints ## Constraints
- Currently, OpenHarmony does not support creation of a Service Extension ability for third-party applications. OpenHarmony does not support creation of a Service Extension ability for third-party applications.
## How to Develop ## How to Develop
1. Create a Service Extension ability. 1. Create a Service Extension ability.
Customize a class that inherits from **ServiceExtensionAbility** in the .ts file and override the lifecycle callbacks of the base class. The code sample is as follows: 2. Customize a class that inherits from **ServiceExtensionAbility** in the .ts file in the directory where the Service Extension ability is defined and override the lifecycle callbacks of the base class. The code sample is as follows:
```js ```js
import rpc from '@ohos.rpc' import rpc from '@ohos.rpc'
...@@ -61,9 +61,9 @@ Customize a class that inherits from **ServiceExtensionAbility** in the .ts file ...@@ -61,9 +61,9 @@ Customize a class that inherits from **ServiceExtensionAbility** in the .ts file
2. Register the Service Extension ability. 2. Register the Service Extension ability.
Declare the Service Extension ability in the **module.json** file by setting its **type** attribute to **service**. Declare the Service Extension ability in the **module.json** file by setting its **type** attribute to **service**.
**module.json configuration example** **module.json configuration example**
```json ```json
"extensionAbilities":[{ "extensionAbilities":[{
...@@ -76,9 +76,7 @@ Declare the Service Extension ability in the **module.json** file by setting its ...@@ -76,9 +76,7 @@ Declare the Service Extension ability in the **module.json** file by setting its
}] }]
``` ```
## Development Example ## Samples
The following sample is provided to help you better understand how to develop a Service Extension ability:
- [`ServiceExtAbility`: Stage Extension Ability Creation and Usage (eTS, API version 9)](https://gitee.com/openharmony/app_samples/tree/master/ability/ServiceExtAbility)
The following sample is provided to help you better understand how to develop Service Extension abilities:
- [`ServiceExtAbility`: Stage Extension Ability Creation and Usage (eTS, API version 9)](https://gitee.com/openharmony/app_samples/tree/master/ability/StageCallAbility)
...@@ -6,6 +6,7 @@ On the basis of the SQLite database, the relational database (RDB) allows you to ...@@ -6,6 +6,7 @@ On the basis of the SQLite database, the relational database (RDB) allows you to
## Available APIs ## Available APIs
For details about RDB APIs, see [Relational Database](../reference/apis/js-apis-data-rdb.md).
### Creating or Deleting an RDB Store ### Creating or Deleting an RDB Store
...@@ -15,10 +16,10 @@ The following table describes the APIs available for creating and deleting an RD ...@@ -15,10 +16,10 @@ The following table describes the APIs available for creating and deleting an RD
| API| Description| | API| Description|
| -------- | -------- | | -------- | -------- |
|getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number,&nbsp;callback:&nbsp;AsyncCallback&lt;RdbStore&gt;):&nbsp;void | Obtains an RDB store. This method uses a callback to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>-&nbsp;**config**: configuration of the RDB store.<br>-&nbsp;**version**: RDB version.<br>-&nbsp;**callback**: callback invoked to return the RDB store obtained.| |getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback&lt;RdbStore&gt;): void | Obtains an RDB store. This method uses a callback to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>- **config**: configuration of the RDB store.<br>- **version**: RDB version.<br>- **callback**: callback invoked to return the RDB store obtained.|
|getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number):&nbsp;Promise&lt;RdbStore&gt; | Obtains an RDB store. This method uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>-&nbsp;**config**: configuration of the RDB store.<br>-&nbsp;**version**: RDB version.| |getRdbStore(config: StoreConfig, version: number): Promise&lt;RdbStore&gt; | Obtains an RDB store. This method uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>- **config**: configuration of the RDB store.<br>- **version**: RDB version.|
|deleteRdbStore(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void | Deletes an RDB store. This method uses a callback to return the result. <br>-&nbsp;**name**: RDB store to delete.<br>-&nbsp;**callback**: callback invoked to return the result.| |deleteRdbStore(name: string, callback: AsyncCallback&lt;void&gt;): void | Deletes an RDB store. This method uses a callback to return the result. <br>- **name**: RDB store to delete.<br>- **callback**: callback invoked to return the result.|
| deleteRdbStore(name:&nbsp;string):&nbsp;Promise&lt;void&gt; | Deletes an RDB store. This method uses a promise to return the result.<br>-&nbsp;**name**: RDB store to delete.| | deleteRdbStore(name: string): Promise&lt;void&gt; | Deletes an RDB store. This method uses a promise to return the result.<br>- **name**: RDB store to delete.|
### Managing Data in an RDB Store ### Managing Data in an RDB Store
...@@ -32,8 +33,8 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th ...@@ -32,8 +33,8 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | insert(name:&nbsp;string,&nbsp;values:&nbsp;ValuesBucket,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Inserts a row of data into a table. This method uses a callback to return the result.<br>-&nbsp;**name**: name of the target table.<br>-&nbsp;**values**: data to be inserted into the table.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.| | RdbStore | insert(name: string, values: ValuesBucket, callback: AsyncCallback&lt;number&gt;):void | Inserts a row of data into a table. This method uses a callback to return the result.<br>- **name**: name of the target table.<br>- **values**: data to be inserted into the table.<br>- **callback**: callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
| RdbStore | insert(name:&nbsp;string,&nbsp;values:&nbsp;ValuesBucket):&nbsp;Promise&lt;number&gt; | Inserts a row of data into a table. This method uses a promise to return the result.<br>-&nbsp;**name**: name of the target table.<br>-&nbsp;**values**: data to be inserted into the table.| | RdbStore | insert(name: string, values: ValuesBucket): Promise&lt;number&gt; | Inserts a row of data into a table. This method uses a promise to return the result.<br>- **name**: name of the target table.<br>- **values**: data to be inserted into the table.|
- **Updating data** - **Updating data**
...@@ -43,8 +44,8 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th ...@@ -43,8 +44,8 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | update(values:&nbsp;ValuesBucket,&nbsp;rdbPredicates:&nbsp;RdbPredicates,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**values**: data to update, which is stored in a **ValuesBucket**.<br>-&nbsp;**rdbPredicates**: conditions for updating data.<br>-&nbsp;**callback**: callback invoked to return the number of rows updated.| | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>- **values**: data to update, which is stored in a **ValuesBucket**.<br>- **rdbPredicates**: conditions for updating data.<br>- **callback**: callback invoked to return the number of rows updated.|
| RdbStore | update(values:&nbsp;ValuesBucket,&nbsp;rdbPredicates:&nbsp;RdbPredicates):&nbsp;Promise\<number> | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**values**: data to update, which is stored in a **ValuesBucket**.<br>-&nbsp;**rdbPredicates**: conditions for updating data.| | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise\<number> | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>- **values**: data to update, which is stored in a **ValuesBucket**.<br>- **rdbPredicates**: conditions for updating data.|
- **Deleting data** - **Deleting data**
...@@ -54,8 +55,8 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th ...@@ -54,8 +55,8 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | delete(rdbPredicates:&nbsp;RdbPredicates,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**rdbPredicates**: conditions for deleting data.<br>-&nbsp;**callback**: callback invoked to return the number of rows deleted.| | RdbStore | delete(rdbPredicates: RdbPredicates, callback: AsyncCallback&lt;number&gt;):void | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>- **rdbPredicates**: conditions for deleting data.<br>- **callback**: callback invoked to return the number of rows updated.|
| RdbStore | delete(rdbPredicates:&nbsp;RdbPredicates):&nbsp;Promise\<number> | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**rdbPredicates**: conditions for deleting data.| | RdbStore | delete(rdbPredicates: RdbPredicates): Promise\<number> | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>- **rdbPredicates**: conditions for deleting data.|
- **Querying data** - **Querying data**
...@@ -68,10 +69,10 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th ...@@ -68,10 +69,10 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | query(rdbPredicates:&nbsp;RdbPredicates,&nbsp;columns:&nbsp;Array,&nbsp;callback:&nbsp;AsyncCallback&lt;ResultSet&gt;):&nbsp;void | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**rdbPredicates**: conditions for querying data.<br>-&nbsp;**columns**: columns to query. If this parameter is not specified, the query applies to all columns.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array, callback: AsyncCallback&lt;ResultSet&gt;): void | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>- **rdbPredicates**: conditions for querying data.<br>- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.<br>- **callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| RdbStore | query(rdbPredicates:&nbsp;RdbPredicates,&nbsp;columns:&nbsp;Array):&nbsp;Promise&lt;ResultSet&gt; | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**rdbPredicates**: conditions for querying data.<br>-&nbsp;**columns**: columns to query. If this parameter is not specified, the query applies to all columns.| | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array): Promise&lt;ResultSet&gt; | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>- **rdbPredicates**: conditions for querying data.<br>- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.|
| RdbStore | querySql(sql:&nbsp;string,&nbsp;bindArgs:&nbsp;Array&lt;ValueType&gt;,&nbsp;callback:&nbsp;AsyncCallback&lt;ResultSet&gt;):void | Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.<br>-&nbsp;**sql**: SQL statement.<br>-&nbsp;**bindArgs**: arguments in the SQL statement.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| | RdbStore | querySql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;ResultSet&gt;):void | Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.<br>- **sql**: SQL statement.<br>- **bindArgs**: arguments in the SQL statement.<br>- **callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| RdbStore | querySql(sql:&nbsp;string,&nbsp;bindArgs?:&nbsp;Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt; | Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.<br>-&nbsp;**sql**: SQL statement.<br>-&nbsp;**bindArgs**: arguments in the SQL statement.| | RdbStore | querySql(sql: string, bindArgs?: Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt; | Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.<br>- **sql**: SQL statement.<br>- **bindArgs**: arguments in the SQL statement.|
### Using Predicates ### Using Predicates
...@@ -81,61 +82,61 @@ The RDB provides **RdbPredicates** for you to set database operation conditions. ...@@ -81,61 +82,61 @@ The RDB provides **RdbPredicates** for you to set database operation conditions.
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbPredicates |inDevices(devices: Array\<string>): RdbPredicates | Specifies remote devices on the network with RDB stores to be synchronized.<br>-&nbsp;**devices**: IDs of the remote devices on the network.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates |inDevices(devices: Array\<string>): RdbPredicates | Specifies remote devices on the network with RDB stores to be synchronized.<br>- **devices**: IDs of the remote devices on the network.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates |inAllDevices(): RdbPredicates | Connects to all remote devices on the network with RDB stores to be synchronized.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates |inAllDevices(): RdbPredicates | Connects to all remote devices on the network with RDB stores to be synchronized.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | equalTo(field:&nbsp;string,&nbsp;value:&nbsp;ValueType):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | equalTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | notEqualTo(field:&nbsp;string,&nbsp;value:&nbsp;ValueType):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | notEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | beginWrap():&nbsp;RdbPredicates | Adds a left parenthesis to the **RdbPredicates**.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** with a left parenthesis.| | RdbPredicates | beginWrap(): RdbPredicates | Adds a left parenthesis to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with a left parenthesis.|
| RdbPredicates | endWrap():&nbsp;RdbPredicates | Adds a right parenthesis to the **RdbPredicates**.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** with a right parenthesis.| | RdbPredicates | endWrap(): RdbPredicates | Adds a right parenthesis to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with a right parenthesis.|
| RdbPredicates | or():&nbsp;RdbPredicates | Adds the OR condition to the **RdbPredicates**.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** with the OR condition.| | RdbPredicates | or(): RdbPredicates | Adds the OR condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the OR condition.|
| RdbPredicates | and():&nbsp;RdbPredicates | Adds the AND condition to the **RdbPredicates**.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** with the AND condition.| | RdbPredicates | and(): RdbPredicates | Adds the AND condition to the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** with the AND condition.|
| RdbPredicates | contains(field:&nbsp;string,&nbsp;value:&nbsp;string):&nbsp;RdbPredicats | Sets the **RdbPredicates** to match a string containing the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified string.| | RdbPredicates | contains(field: string, value: string): RdbPredicats | Sets the **RdbPredicates** to match a string containing the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string.|
| RdbPredicates | beginsWith(field:&nbsp;string,&nbsp;value:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match a string that starts with the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | beginsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that starts with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | endsWith(field:&nbsp;string,&nbsp;value:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match a string that ends with the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | endsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that ends with the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | isNull(field:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field whose value is null.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | isNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is null.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | isNotNull(field:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field whose value is not null.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | isNotNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is not null.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | like(field:&nbsp;string,&nbsp;value:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match a string that is similar to the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | like(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that is similar to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | glob(field:&nbsp;string,&nbsp;value:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the specified string.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | glob(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match the specified string.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | between(field:&nbsp;string,&nbsp;low:&nbsp;ValueType,&nbsp;high:&nbsp;ValueType):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**low**: minimum value that matches the **RdbPredicates**.<br>-&nbsp;**high**: maximum value that matches the **RdbPredicates**.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | between(field: string, low: ValueType, high: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.<br>- **field**: column name in the database table.<br>- **low**: minimum value that matches the **RdbPredicates**.<br>- **high**: maximum value that matches the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | notBetween(field:&nbsp;string,&nbsp;low:&nbsp;ValueType,&nbsp;high:&nbsp;ValueType):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**low**: minimum value that matches the **RdbPredicates**.<br>-&nbsp;**high**: maximum value that matches the **RdbPredicates**.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.<br>- **field**: column name in the database table.<br>- **low**: minimum value that matches the **RdbPredicates**.<br>- **high**: maximum value that matches the **RdbPredicates**.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | greaterThan(field:&nbsp;string,&nbsp;value:&nbsp;ValueType):&nbsp;RdbPredicatesgr | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | greaterThan(field: string, value: ValueType): RdbPredicatesgr | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | lessThan(field:&nbsp;string,&nbsp;value:&nbsp;ValueType):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | lessThan(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | greaterThanOrEqualTo(field:&nbsp;string,&nbsp;value:&nbsp;ValueType):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | lessThanOrEqualTo(field:&nbsp;string,&nbsp;value:&nbsp;ValueType):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: value specified.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.<br>- **field**: column name in the database table.<br>- **value**: value specified.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | orderByAsc(field:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in ascending order.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | orderByAsc(field: string): RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in ascending order.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | orderByDesc(field:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in descending order.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | orderByDesc(field: string): RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in descending order.<br>- **field**: column name in the database table.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | distinct():&nbsp;RdbPredicates | Sets the **RdbPredicates** to filter out duplicate records.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that can filter out duplicate records.| | RdbPredicates | distinct(): RdbPredicates | Sets the **RdbPredicates** to filter out duplicate records.<br>- **RdbPredicates**: returns a **RdbPredicates** object that can filter out duplicate records.|
| RdbPredicates | limitAs(value:&nbsp;number):&nbsp;RdbPredicates | Sets the **RdbPredicates** to specify the maximum number of records.<br>-&nbsp;**value**: maximum number of records.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that can be used to set the maximum number of records.| | RdbPredicates | limitAs(value: number): RdbPredicates | Sets the **RdbPredicates** to specify the maximum number of records.<br>- **value**: maximum number of records.<br>- **RdbPredicates**: returns a **RdbPredicates** object that can be used to set the maximum number of records.|
| RdbPredicates | offsetAs(rowOffset:&nbsp;number):&nbsp;RdbPredicates | Sets the **RdbPredicates** to specify the start position of the returned result.<br>-&nbsp;**rowOffset**: start position of the returned result. The value is a positive integer.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that specifies the start position of the returned result.| | RdbPredicates | offsetAs(rowOffset: number): RdbPredicates | Sets the **RdbPredicates** to specify the start position of the returned result.<br>- **rowOffset**: start position of the returned result. The value is a positive integer.<br>- **RdbPredicates**: returns a **RdbPredicates** object that specifies the start position of the returned result.|
| RdbPredicates | groupBy(fields:&nbsp;Array&lt;string&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to group rows that have the same value into summary rows.<br>-&nbsp;**fields**: names of the columns grouped for querying data.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that groups rows with the same value.| | RdbPredicates | groupBy(fields: Array&lt;string&gt;): RdbPredicates | Sets the **RdbPredicates** to group rows that have the same value into summary rows.<br>- **fields**: names of the columns grouped for querying data.<br>- **RdbPredicates**: returns a **RdbPredicates** object that groups rows with the same value.|
| RdbPredicates | indexedBy(indexName:&nbsp;string):&nbsp;RdbPredicates | Sets the **RdbPredicates** to specify the index column.<br>-&nbsp;**indexName**: name of the index column.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that specifies the index column.| | RdbPredicates | indexedBy(indexName: string): RdbPredicates | Sets the **RdbPredicates** to specify the index column.<br>- **indexName**: name of the index column.<br>- **RdbPredicates**: returns a **RdbPredicates** object that specifies the index column.|
| RdbPredicates | in(field:&nbsp;string,&nbsp;value:&nbsp;Array&lt;ValueType&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: array of **ValueType** to match.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | in(field: string, value: Array&lt;ValueType&gt;): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.<br>- **field**: column name in the database table.<br>- **value**: array of **ValueType** to match.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | notIn(field:&nbsp;string,&nbsp;value:&nbsp;Array&lt;ValueType&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: array of **ValueType** to match.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.| | RdbPredicates | notIn(field: string, value: Array&lt;ValueType&gt;): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.<br>- **field**: column name in the database table.<br>- **value**: array of **ValueType** to match.<br>- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
### Using the Result Set ### Using the Result Set
A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**. A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**.
> **NOTICE**<br> > ![icon-notice.gif](public_sys-resources/icon-notice.gif) **NOTICE**<br>
> After a result set is used, you must call the **close()** method to close it explicitly. > After a result set is used, you must call the **close()** method to close it explicitly.
**Table 7** APIs for using the result set **Table 7** APIs for using the result set
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ResultSet | goTo(offset:number):&nbsp;boolean | Moves the result set forwards or backwards by the specified offset relative to its current position.| | ResultSet | goTo(offset:number): boolean | Moves the result set forwards or backwards by the specified offset relative to its current position.|
| ResultSet | goToRow(position:&nbsp;number):&nbsp;boolean | Moves the result set to the specified row.| | ResultSet | goToRow(position: number): boolean | Moves the result set to the specified row.|
| ResultSet | goToNextRow():&nbsp;boolean | Moves the result set to the next row.| | ResultSet | goToNextRow(): boolean | Moves the result set to the next row.|
| ResultSet | goToPreviousRow():&nbsp;boolean | Moves the result set to the previous row.| | ResultSet | goToPreviousRow(): boolean | Moves the result set to the previous row.|
| ResultSet | getColumnIndex(columnName:&nbsp;string):&nbsp;number | Obtains the column index based on the specified column name.| | ResultSet | getColumnIndex(columnName: string): number | Obtains the column index based on the specified column name.|
| ResultSet | getColumnName(columnIndex:&nbsp;number):&nbsp;string | Obtains the column name based on the specified column index.| | ResultSet | getColumnName(columnIndex: number): string | Obtains the column name based on the specified column index.|
| ResultSet | goToFirstRow():&nbsp;boolean | Checks whether the result set is located in the first row.| | ResultSet | goToFirstRow(): boolean | Checks whether the result set is located in the first row.|
| ResultSet | goToLastRow():&nbsp;boolean | Checks whether the result set is located in the last row.| | ResultSet | goToLastRow(): boolean | Checks whether the result set is located in the last row.|
| ResultSet | getString(columnIndex:&nbsp;number):&nbsp;string | Obtains the value in the specified column of the current row, in a string.| | ResultSet | getString(columnIndex: number): string | Obtains the value in the specified column of the current row, in a string.|
| ResultSet | getBlob(columnIndex:&nbsp;number):&nbsp;Uint8Array | Obtains the values in the specified column of the current row, in a byte array.| | ResultSet | getBlob(columnIndex: number): Uint8Array | Obtains the values in the specified column of the current row, in a byte array.|
| ResultSet | getDouble(columnIndex:&nbsp;number):&nbsp;number | Obtains the values in the specified column of the current row, in double.| | ResultSet | getDouble(columnIndex: number): number | Obtains the values in the specified column of the current row, in double.|
| ResultSet | isColumnNull(columnIndex:&nbsp;number):&nbsp;boolean | Checks whether the value in the specified column of the current row is null.| | ResultSet | isColumnNull(columnIndex: number): boolean | Checks whether the value in the specified column of the current row is null.|
| ResultSet | close():&nbsp;void | Closes the result set.| | ResultSet | close(): void | Closes the result set.|
...@@ -147,8 +148,8 @@ A result set can be regarded as a row of data in the queried results. It allows ...@@ -147,8 +148,8 @@ A result set can be regarded as a row of data in the queried results. It allows
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | setDistributedTables(tables: Array\<string>, callback: AsyncCallback\<void>): void | Sets a list of distributed tables. This method uses a callback to return the result.<br>- &nbsp;**tables**: names of the distributed tables to set.<br>-&nbsp;**callback**: callback invoked to return the result.| | RdbStore | setDistributedTables(tables: Array\<string>, callback: AsyncCallback\<void>): void; | Sets a list of distributed tables. This method uses a callback to return the result.<br>- **tables**: names of the distributed tables to set.<br>- **callback**: callback invoked to return the result.|
| RdbStore | setDistributedTables(tables: Array\<string>): Promise\<void> | Sets a list of distributed tables. This method uses a promise to return the result.<br>- &nbsp;**tables**: names of the distributed tables to set.| | RdbStore | setDistributedTables(tables: Array\<string>): Promise\<void>; | Sets a list of distributed tables. This method uses a promise to return the result.<br>- **tables**: names of the distributed tables to set.|
**Obtaining the Distributed Table Name for a Remote Device** **Obtaining the Distributed Table Name for a Remote Device**
...@@ -158,8 +159,8 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -158,8 +159,8 @@ You can obtain the distributed table name for a remote device based on the local
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | obtainDistributedTableName(device: string, table: string, callback: AsyncCallback\<string>): void | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is used to query the RDB store of the remote device. This method uses a callback to return the result.<br>-&nbsp;**device**: remote device.<br>- &nbsp;**table**: local table name.<br>- &nbsp;**callback**: callback used to return the result. If the operation is successful, the distributed table name of the remote device will be returned. | | RdbStore | obtainDistributedTableName(device: string, table: string, callback: AsyncCallback\<string>): void; | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is required when the database of a remote device is queried. This API uses an asynchronous callback to return the result.<br>- **device**: remote device.<br>- **table**: local table name.<br>- **callback**: callback used to return the result. If the operation is successful, the distributed table name of the remote device will be returned.|
| RdbStore | obtainDistributedTableName(device: string, table: string): Promise\<string> | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is used to query the RDB store of the remote device. This method uses a promise to return the result.<br>-&nbsp;**device**: remote device.<br>- &nbsp;**table**: local table name.| | RdbStore | obtainDistributedTableName(device: string, table: string): Promise\<string>; | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is used to query the RDB store of the remote device. This method uses a promise to return the result.<br>- **device**: remote device.<br>- **table**: local table name.|
**Synchronizing Data Between Devices** **Synchronizing Data Between Devices**
...@@ -167,8 +168,8 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -167,8 +168,8 @@ You can obtain the distributed table name for a remote device based on the local
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void | Synchronizes data between devices. This method uses a callback to return the result.<br>-&nbsp;**mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>-&nbsp;**predicates**: data and devices to be synchronized.<br>-&nbsp;**callback**: callback invoked to return the result. In the result, **string** indicates the device ID, and **number** indicates the synchronization status of each device. The value **0** indicates a success, and other values indicate a failure.| | RdbStore | sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void;| Synchronizes data between devices. This method uses a callback to return the result.<br>- **mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>- **predicates**: data and devices to be synchronized.<br>- **callback**: callback invoked to return the result. In the result, **string** indicates the device ID, and **number** indicates the synchronization status of each device. The value **0** indicates a success, and other values indicate a failure.|
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>> | Synchronizes data between devices. This method uses a promise to return the result.<br>-&nbsp;**mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>-&nbsp;**predicates**: data and devices to be synchronized. | | RdbStore | sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>>;| Synchronizes data between devices. This method uses a promise to return the result.<br>- **mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>- **predicates**: data and devices to be synchronized. |
**Registering an RDB Store Observer** **Registering an RDB Store Observer**
...@@ -176,7 +177,7 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -176,7 +177,7 @@ You can obtain the distributed table name for a remote device based on the local
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore |on(event: 'dataChange', type: SubscribeType, observer: Callback<Array\<string>>): void| Registers an observer for this RDB store to subscribe to distributed data changes. When data in the RDB store changes, a callback will be invoked to return the data changes.<br>-&nbsp;**type**: subscription type. **SUBSCRIBE\_TYPE\_REMOTE** means to subscribe to remote data changes.<br>-&nbsp;**observer**: observer that listens for data changes in the RDB store.| | RdbStore |on(event: 'dataChange', type: SubscribeType, observer: Callback<Array\<string>>): void;| Registers an observer for this RDB store to subscribe to distributed data changes. When data in the RDB store changes, a callback will be invoked to return the data changes.<br>- **type**: subscription type. **SUBSCRIBE\_TYPE\_REMOTE** means to subscribe to remote data changes.<br>- **observer**: observer that listens for data changes in the RDB store.|
**Unregistering an RDB Store Observer** **Unregistering an RDB Store Observer**
...@@ -184,7 +185,7 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -184,7 +185,7 @@ You can obtain the distributed table name for a remote device based on the local
| Class| API| Description| | Class| API| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| RdbStore |off(event:'dataChange', type: SubscribeType, observer: Callback<Array\<string>>): void| Unregisters the observer of the specified type for the RDB store. This method uses a callback to return the result.<br>- &nbsp;**type**: subscription type. **SUBSCRIBE\_TYPE\_REMOTE** means to subscribe to remote data changes.<br>- &nbsp;**observer**: observer to unregister.| | RdbStore |off(event:'dataChange', type: SubscribeType, observer: Callback<Array\<string>>): void;| Unregisters the observer of the specified type for the RDB store. This API uses a callback to return the result.<br>- **type**: subscription type. **SUBSCRIBE\_TYPE\_REMOTE** means to subscribe to remote data changes.<br>- **observer**: observer to unregister.|
## How to Develop ## How to Develop
...@@ -202,7 +203,7 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -202,7 +203,7 @@ You can obtain the distributed table name for a remote device based on the local
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {name: "rdbstore.db",} const STORE_CONFIG = {name: "rdbstore.db",}
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) { data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(CREATE_TABLE_TEST) rdbStore.executeSql(CREATE_TABLE_TEST )
console.info('create table done.') console.info('create table done.')
}) })
``` ```
...@@ -306,3 +307,8 @@ You can obtain the distributed table name for a remote device based on the local ...@@ -306,3 +307,8 @@ You can obtain the distributed table name for a remote device based on the local
let tableName = rdbStore.obtainDistributedTableName(deviceId, "test"); let tableName = rdbStore.obtainDistributedTableName(deviceId, "test");
let resultSet = rdbStore.querySql("SELECT * FROM " + tableName) let resultSet = rdbStore.querySql("SELECT * FROM " + tableName)
``` ```
## Samples
The following samples are provided for you to better understand the RDB development:
- [`Rdb`: eTS RDB (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/Rdb)
- [`DistributedRdb`: eTS Distributed Relational Database (API8)](https://gitee.com/openharmony/app_samples/tree/master/data/DistributedRdb)
- [Relational Database](https://gitee.com/openharmony/codelabs/tree/master/Data/JSRelationshipData)
# video # video
> **NOTE**<br> > **NOTE**
> >
> - This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version. > - This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
> >
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
> ] > ]
> ``` > ```
The **\<Video>** component provides a video player. The **\<video>** component provides a video player.
## Child Components ## Child Components
...@@ -76,7 +76,8 @@ In addition to the [universal methods](../arkui-js/js-components-common-methods. ...@@ -76,7 +76,8 @@ In addition to the [universal methods](../arkui-js/js-components-common-methods.
| pause | - | Pauses a video.| | pause | - | Pauses a video.|
| setCurrentTime | {&nbsp;currenttime:&nbsp;value&nbsp;} | Sets the video playback position, in seconds.| | setCurrentTime | {&nbsp;currenttime:&nbsp;value&nbsp;} | Sets the video playback position, in seconds.|
> **NOTE**<br> > **NOTE**
>
> The methods in the above table can be called after the **attached** callback is invoked. > The methods in the above table can be called after the **attached** callback is invoked.
## Example ## Example
...@@ -89,7 +90,7 @@ In addition to the [universal methods](../arkui-js/js-components-common-methods. ...@@ -89,7 +90,7 @@ In addition to the [universal methods](../arkui-js/js-components-common-methods.
onpaues='pauesCallback' onfinish='finishCallback' onerror='errorCallback' onpaues='pauesCallback' onfinish='finishCallback' onerror='errorCallback'
onseeking='seekingCallback' onseeked='seekedCallback' onseeking='seekingCallback' onseeked='seekedCallback'
ontimeupdate='timeupdateCallback' ontimeupdate='timeupdateCallback'
style="object-fit:fit; width:80%; height:400px;" style="object-fit:fill; width:80%; height:400px;"
onclick="change_start_pause"> onclick="change_start_pause">
</video> </video>
</div> </div>
......
...@@ -54,7 +54,7 @@ ImageAnimator() ...@@ -54,7 +54,7 @@ ImageAnimator()
## Events ## Events
| Name | Description | | Name | Description |
| -------- | -------- | -------- | | -------- | -------- |
| onStart() =&gt; void | Triggered when the animation starts to play. | | onStart() =&gt; void | Triggered when the animation starts to play. |
| onPause() =&gt; void | Triggered when the animation playback is paused. | | onPause() =&gt; void | Triggered when the animation playback is paused. |
| onRepeat() =&gt; void | Triggered when the animation playback is repeated. | | onRepeat() =&gt; void | Triggered when the animation playback is repeated. |
......
# Progress # Progress
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **&lt;Progress&gt;** component is used to provide a progress bar that displays the progress of content loading or an operation. The **\<Progress>** component is used to provide a progress bar that displays the progress of content loading or an operation.
## Required Permissions ## Required Permissions
...@@ -15,17 +16,17 @@ None ...@@ -15,17 +16,17 @@ None
## Child Components ## Child Components
None Not supported
## APIs ## APIs
Progress(value: { value: number, total?: number, type?: ProgressType}) Progress(value: {value: number, total?: number, type?: ProgressType})
Creates a progress bar. Creates a progress bar.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| value | number | Yes | - | Current progress. | | value | number | Yes | - | Current progress. |
| total | number | No | 100 | Total progress. | | total | number | No | 100 | Total progress. |
...@@ -33,7 +34,7 @@ Creates a progress bar. ...@@ -33,7 +34,7 @@ Creates a progress bar.
- ProgressType enums - ProgressType enums
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | -------- |
| Linear | Linear type. | | Linear | Linear type. |
| Ring<sup>8+</sup> | Ring type without scale. The ring fills up as the progress increases. | | Ring<sup>8+</sup> | Ring type without scale. The ring fills up as the progress increases. |
...@@ -54,7 +55,8 @@ Creates a progress bar. ...@@ -54,7 +55,8 @@ Creates a progress bar.
## Example ## Example
``` ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct ProgressExample { struct ProgressExample {
...@@ -88,8 +90,8 @@ struct ProgressExample { ...@@ -88,8 +90,8 @@ struct ProgressExample {
Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Capsule Progress').fontSize(9).fontColor(0xCCCCCC).width('90%')
Row({ space: 40 }) { Row({ space: 40 }) {
Progress({ value: 10, type: ProgressType.Capsule }).width(100) Progress({ value: 10, type: ProgressType.Capsule }).width(100).height(50)
Progress({ value: 20, total: 150, type: ProgressType.Capsule }).color(Color.Grey).value(50).width(100) Progress({ value: 20, total: 150, type: ProgressType.Capsule }).color(Color.Grey).value(50).width(100).height(50)
} }
}.width('100%').margin({ top: 30 }) }.width('100%').margin({ top: 30 })
} }
......
# TextArea # TextArea
> **NOTE**<br> > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -20,7 +21,7 @@ Not supported ...@@ -20,7 +21,7 @@ Not supported
## APIs ## APIs
TextArea(value?:{placeholder?: string controller?: TextAreaController}) TextArea(value?:{placeholder?: string, controller?: TextAreaController})
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
...@@ -93,10 +94,11 @@ Sets the position of the caret. ...@@ -93,10 +94,11 @@ Sets the position of the caret.
@Entry @Entry
@Component @Component
struct TextAreaExample1 { struct TextAreaExample1 {
controller: TextAreaController = new TextAreaController()
@State text: string = '' @State text: string = ''
build() { build() {
Column() { Column() {
TextArea({ placeholder: 'input your word'}) TextArea({ placeholder: 'input your word', controller: this.controller})
.placeholderColor("rgb(0,0,225)") .placeholderColor("rgb(0,0,225)")
.placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic }) .placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic })
.textAlign(TextAlign.Center) .textAlign(TextAlign.Center)
...@@ -112,6 +114,7 @@ struct TextAreaExample1 { ...@@ -112,6 +114,7 @@ struct TextAreaExample1 {
}) })
.onChange((value: string) => { .onChange((value: string) => {
this.text = value this.text = value
this.controller.caretPosition(-1)
}) })
Text(this.text).width('90%') Text(this.text).width('90%')
} }
......
# TextInput # TextInput
> **NOTE**<br/> > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
...@@ -39,9 +40,8 @@ In addition to universal attributes, the following attributes are supported. ...@@ -39,9 +40,8 @@ In addition to universal attributes, the following attributes are supported.
| placeholderFont | {<br/>size?: Length,<br/>weight?: number\|[FontWeight](ts-universal-attributes-text-style.md),<br/>family?: string,<br/>style?: [FontStyle](ts-universal-attributes-text-style.md)<br/>} | - | Placeholder text style.<br/>- **size**: font size. If the value is of the number type, the unit fp is used.<br/>- **weight**: font weight. For the number type, the value ranges from 100 to 900, at an interval of 100. The default value is **400**. A larger value indicates a larger font weight.<br/>- **family**: font family. Use commas (,) to separate multiple fonts, for example, **'Arial, sans-serif'**. The priority of the fonts is the sequence in which they are placed.<br/>- **style**: font style. | | placeholderFont | {<br/>size?: Length,<br/>weight?: number\|[FontWeight](ts-universal-attributes-text-style.md),<br/>family?: string,<br/>style?: [FontStyle](ts-universal-attributes-text-style.md)<br/>} | - | Placeholder text style.<br/>- **size**: font size. If the value is of the number type, the unit fp is used.<br/>- **weight**: font weight. For the number type, the value ranges from 100 to 900, at an interval of 100. The default value is **400**. A larger value indicates a larger font weight.<br/>- **family**: font family. Use commas (,) to separate multiple fonts, for example, **'Arial, sans-serif'**. The priority of the fonts is the sequence in which they are placed.<br/>- **style**: font style. |
| enterKeyType | EnterKeyType | EnterKeyType.Done | How the Enter key is labeled. | | enterKeyType | EnterKeyType | EnterKeyType.Done | How the Enter key is labeled. |
| caretColor | Color | - | Color of the caret (also known as the text insertion cursor). | | caretColor | Color | - | Color of the caret (also known as the text insertion cursor). |
| maxLength<sup>8+</sup> | number | - | Maximum number of characters in the text input. | | maxLength | number | - | Maximum number of characters in the text input. |
| inputFilter<sup>8+</sup> | {<br/>value: [ResourceStr](../../ui/ts-types.md)<sup>8+</sup>,<br/>error?: (value: string)<br/>} | - | Regular expression for input filtering. Only inputs that comply with the regular expression can be displayed. Other inputs are ignored. The specified regular expression can match single characters, but not strings. Example: ^(? =.\*\d)(? =.\*[a-z])(? =.\*[A-Z]).{8,10}$. Strong passwords containing 8 to 10 characters cannot be filtered.<br/>- **value**: regular expression to set.<br/>- **error**: error message containing the ignored content returned when regular expression matching fails. | | inputFilter<sup>8+</sup> | {<br/>value: [ResourceStr](../../ui/ts-types.md)<sup>8+</sup>,<br/>error?: (value: string)<br/>} | - | Regular expression for input filtering. Only inputs that comply with the regular expression can be displayed. Other inputs are ignored. The specified regular expression can match single characters, but not strings. Example: ^(? =.\*\d)(? =.\*[a-z])(? =.\*[A-Z]).{8,10}$. Strong passwords containing 8 to 10 characters cannot be filtered.<br/>- **value**: regular expression to set.<br/>- **error**: error message containing the ignored content returned when regular expression matching fails. |
| copyOption<sup>9+</sup> | boolean\|[CopyOption](ts-basic-components-text.md) | true | Whether copy and paste is allowed. |
- EnterKeyType enums - EnterKeyType enums
| Name | Description | | Name | Description |
...@@ -75,10 +75,10 @@ In addition to universal attributes, the following attributes are supported. ...@@ -75,10 +75,10 @@ In addition to universal attributes, the following attributes are supported.
### TextInputController<sup>8+</sup> ### TextInputController<sup>8+</sup>
Implements the controller of the **&lt;TextInput&gt;** component. Implements the controller of the **\<TextInput>** component.
### Objects to Import #### Objects to Import
``` ```
...@@ -86,7 +86,7 @@ controller: TextInputController = new TextInputController() ...@@ -86,7 +86,7 @@ controller: TextInputController = new TextInputController()
``` ```
### caretPosition #### caretPosition
caretPosition(value: number): void caretPosition(value: number): void
...@@ -113,10 +113,9 @@ struct TextInputExample1 { ...@@ -113,10 +113,9 @@ struct TextInputExample1 {
build() { build() {
Column() { Column() {
TextArea({ placeholder: 'input your word' }) TextInput({ placeholder: 'input your word' })
.placeholderColor("rgb(0,0,225)") .placeholderColor("rgb(0,0,225)")
.placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic }) .placeholderFont({ size: 30, weight: 100, family: 'cursive', style: FontStyle.Italic })
.textAlign(TextAlign.Center)
.caretColor(Color.Blue) .caretColor(Color.Blue)
.height(50) .height(50)
.fontSize(30) .fontSize(30)
......
...@@ -48,7 +48,7 @@ Not supported ...@@ -48,7 +48,7 @@ Not supported
| textZoomAtio | number | 100 | Text zoom ratio of the page. The default value is **100**, which indicates 100%. | | textZoomAtio | number | 100 | Text zoom ratio of the page. The default value is **100**, which indicates 100%. |
| userAgent | string | - | User agent. | | userAgent | string | - | User agent. |
> **NOTE**<br> > **NOTE**<br>
> >
> Only the following universal attributes are supported: [width](ts-universal-attributes-size.md#Attributes), [height](ts-universal-attributes-size.md#Attributes), [padding](ts-universal-attributes-size.md#Attributes), [margin](ts-universal-attributes-size.md#Attributes), and [border](ts-universal-attributes-border.md#Attributes). > Only the following universal attributes are supported: [width](ts-universal-attributes-size.md#Attributes), [height](ts-universal-attributes-size.md#Attributes), [padding](ts-universal-attributes-size.md#Attributes), [margin](ts-universal-attributes-size.md#Attributes), and [border](ts-universal-attributes-border.md#Attributes).
...@@ -74,97 +74,85 @@ The universal events are not supported. ...@@ -74,97 +74,85 @@ The universal events are not supported.
| onShowFileSelector(callback: (event?: { result: [FileSelectorResult](#fileselectorresult), fileSelector: [FileSelectorParam](#fileselectorparam) }) => void) | <p>Triggered to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.<br>**result**: file selection result to be sent to the web component.<br>**fileSelector**: information about the file selector.</p> | | onShowFileSelector(callback: (event?: { result: [FileSelectorResult](#fileselectorresult), fileSelector: [FileSelectorParam](#fileselectorparam) }) => void) | <p>Triggered to process an HTML form whose input type is **file**, in response to the tapping of the **Select File** button.<br>**result**: file selection result to be sent to the web component.<br>**fileSelector**: information about the file selector.</p> |
| onUrlLoadIntercept(callback: (event?: { data:string \| [WebResourceRequest](#webresourcerequest) }) => boolean) | <p>Triggered before the **\<Web>** component loads the URL to determine whether to block the access. The callback returns **true** if the access is blocked, and **false** otherwise.<br>**data**: URL information.</p> | | onUrlLoadIntercept(callback: (event?: { data:string \| [WebResourceRequest](#webresourcerequest) }) => boolean) | <p>Triggered before the **\<Web>** component loads the URL to determine whether to block the access. The callback returns **true** if the access is blocked, and **false** otherwise.<br>**data**: URL information.</p> |
### ConsoleMessage ## ConsoleMessage
- APIs
| Name | Description | | Name | Description |
| ------------------------------- | ---------------------- | | ------------------------------- | ---------------------- |
| getLineNumber(): number | Obtains the number of rows in the **ConsoleMessage**. | | getLineNumber(): number | Obtains the number of rows in the **ConsoleMessage**. |
| getMessage(): string | Obtains the log information of the **ConsoleMessage**.| | getMessage(): string | Obtains the log information of the **ConsoleMessage**.|
| getMessageLevel(): MessageLevel | Obtains the log information level of the **ConsoleMessage**.| | getMessageLevel(): [MessageLevel](#messagelevel-enums) | Obtains the log information level of the **ConsoleMessage**.|
| getSourceId(): string | Obtains the path and name of the web page source file. | | getSourceId(): string | Obtains the path and name of the web page source file. |
- MessageLevel enums ## MessageLevel Enums
| Name | Description | | Name | Description |
| ----- | :---- | | ----- | :---- |
| Debug | Debug level.| | Debug | Debug level.|
| Error | Error level.| | Error | Error level.|
| Info | Information level.| | Info | Information level.|
| Log | Log level.| | Log | Log level.|
| Warn | Warning level. | | Warn | Warning level. |
### JsResult ## JsResult
Provides the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box. Provides the result returned to the **\<Web>** component to indicate the user operation performed in the dialog box.
- APIs | Name | Description |
| --------------------- | ----------------------- |
| Name | Description | | handleCancel(): void | <p>The user's cancel operation in the dialog box.</p> |
| --------------------- | ----------------------- | | handleConfirm(): void | <p>The user's confirm operation in the dialog box.</p> |
| handleCancel(): void | <p>The user's cancel operation in the dialog box.</p> |
| handleConfirm(): void | <p>The user's confirm operation in the dialog box.</p> |
### WebResourceError ## WebResourceError
- APIs | Name | Description |
| ---------------------- | ------------ |
| Name | Description | | getErrorCode(): number | Obtains the error code for resource loading. |
| ---------------------- | ------------ | | getErrorInfo(): string | Obtains error information about resource loading.|
| getErrorCode(): number | Obtains the error code for resource loading. |
| getErrorInfo(): string | Obtains error information about resource loading.|
### WebResourceRequest
- APIs ## WebResourceRequest
| Name | Description | | Name | Description |
| ---------------------------------------- | -------------------- | | ---------------------------------------- | -------------------- |
| getRequestHeader(): Array\<[Header](#header)\> | Obtains the information about the resource request header. | | getRequestHeader(): Array\<[Header](#header)\> | Obtains the information about the resource request header. |
| getRequestUrl(): string | Obtains the URL of the resource request. | | getRequestUrl(): string | Obtains the URL of the resource request. |
| isMainFrame(): boolean | Checks whether the resource request is in the main frame. | | isMainFrame(): boolean | Checks whether the resource request is in the main frame. |
| isRedirect(): boolean | Checks whether the resource request is redirected by the server. | | isRedirect(): boolean | Checks whether the resource request is redirected by the server. |
| isRequestGesture(): boolean | Checks whether the resource request is associated with a gesture (for example, a tap).| | isRequestGesture(): boolean | Checks whether the resource request is associated with a gesture (for example, a tap).|
### Header ## Header
Describes the request/response header returned by the **\<Web>** component. Describes the request/response header returned by the **\<Web>** component.
- Parameters | Name | Type | Description |
| ----------- | ------ | ------------- |
| Name | Type | Description | | headerKey | string | Key of the request/response header. |
| ----------- | ------ | ------------- | | headerValue | string | Value of the request/response header.|
| headerKey | string | Key of the request/response header. |
| headerValue | string | Value of the request/response header.|
### WebResourceResponse
- APIs ## WebResourceResponse
| Name | Description | | Name | Description |
| ---------------------------------------- | ------------------ | | ---------------------------------------- | ------------------ |
| getReasonMessage(): string | Obtains the status code description of the resource response. | | getReasonMessage(): string | Obtains the status code description of the resource response. |
| getResponseCode(): number | Obtains the status code of the resource response. | | getResponseCode(): number | Obtains the status code of the resource response. |
| getResponseData(): string | Obtains the data in the resource response. | | getResponseData(): string | Obtains the data in the resource response. |
| getResponseEncoding(): string | Obtains the encoding of the resource response. | | getResponseEncoding(): string | Obtains the encoding of the resource response. |
| getResponseHeader(): Array\<[Header](#header)\> | Obtains the resource response header. | | getResponseHeader(): Array\<[Header](#header)\> | Obtains the resource response header. |
| getResponseMimeType(): string | Obtains the media (MIME) type of the resource response.| | getResponseMimeType(): string | Obtains the media (MIME) type of the resource response.|
### RenderExitReason ## RenderExitReason
Explains why the rendering process exits. Explains why the rendering process exits.
| Name | Description | | Name | Description |
| -------------------------- | ----------------- | | -------------------------- | ----------------- |
| ProcessAbnormalTermination | The rendering process exits abnormally. | | PROCESS_ABNORMAL_TERMINATION | The rendering process exits abnormally. |
| ProcessWasKilled | The rendering process receives a SIGKILL message or is manually terminated.| | PROCESS_WAS_KILLED | The rendering process receives a SIGKILL message or is manually terminated.|
| ProcessCrashed | The rendering process crashes due to a segmentation error or other errors. | | PROCESS_CRASHED | The rendering process crashes due to a segmentation error or other errors. |
| ProcessOom | The program memory is running low. | | PROCESS_OOM | The program memory is running low. |
| ProcessExitUnknown | Other reason. | | PROCESS_EXIT_UNKNOWN | Other reason. |
### MixedMode ## MixedMode
| Name | Description | | Name | Description |
| ---------- | ---------------------------------- | | ---------- | ---------------------------------- |
...@@ -172,7 +160,7 @@ Explains why the rendering process exits. ...@@ -172,7 +160,7 @@ Explains why the rendering process exits.
| Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. | | Compatible | HTTP and HTTPS hybrid content can be loaded in compatibility mode. This means that some insecure content may be loaded. |
| None | HTTP and HTTPS hybrid content cannot be loaded. | | None | HTTP and HTTPS hybrid content cannot be loaded. |
### CacheMode ## CacheMode
| Name | Description | | Name | Description |
| ------- | ------------------------------------ | | ------- | ------------------------------------ |
| Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.| | Default | The cache that has not expired is used to load the resources. If the resources do not exist in the cache, they will be obtained from the Internet.|
...@@ -180,32 +168,28 @@ Explains why the rendering process exits. ...@@ -180,32 +168,28 @@ Explains why the rendering process exits.
| Online | The cache is not used to load the resources. All resources are obtained from the Internet. | | Online | The cache is not used to load the resources. All resources are obtained from the Internet. |
| Only | The cache alone is used to load the resources. | | Only | The cache alone is used to load the resources. |
### FileSelectorResult ## FileSelectorResult
Notifies the **\<Web>** component of the file selection result. Notifies the **\<Web>** component of the file selection result.
- APIs | Name | Description |
| ---------------------------------------------- | ------------------------------------------------------------ |
| Name | Description | | handleFileList(fileList: Array\<string>): void | Instructs the **\<Web>** component to select a file.<br>**fileList**: list of files to operate. |
| ---------------------------------------------- | ------------------------------------------------------------ |
| handleFileList(fileList: Array\<string>): void | Instructs the **\<Web>** component to select a file.<br>**fileList**: list of files to operate. |
### FileSelectorParam
- APIs
| Name | Description | ## FileSelectorParam
| -------------------------------- | ------------ | | Name | Description |
| getTitle(): string | Obtains the title of the file selector. | | -------------------------------- | ------------ |
| getMode(): FileSelectorMode | Obtains the mode of the file selector. | | title(): string | Title of the file selector. |
| getAcceptType(): Array\<string\> | Obtains the file filtering type. | | mode(): FileSelectorMode | Mode of the file selector. |
| isCapture(): boolean | Checks whether multimedia capabilities are invoked.| | acceptType(): Array\<string\> | File filtering type. |
| isCapture(): boolean | Whether multimedia capabilities are invoked.|
### FileSelectorMode ## FileSelectorMode
| Name | Description | | Name | Description |
| -------------------- | ---------- | | -------------------- | ---------- |
| FileOpenMode | Open and upload a file. | | FILE_OPEN_MODE | Open and upload a file. |
| FileOpenMultipleMode | Open and upload multiple files. | | FILE_OPEN_MULTIPLE_MODE | Open and upload multiple files. |
| FileOpenFolderMode | Open and upload a folder.| | FILE_OPEN_FOLDER_MODE | Open and upload a folder.|
| FileSaveMode | Save a file. | | FILE_SAVE_MODE | Save a file. |
## WebController ## WebController
......
# Navigator # Navigator
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The **&lt;Navigator&gt;** component provides redirection. The **\<Navigator>** component provides redirection to the target page.
## Required Permissions ## Required Permissions
...@@ -25,42 +26,43 @@ Navigator(value?: {target: string, type?: NavigationType}) ...@@ -25,42 +26,43 @@ Navigator(value?: {target: string, type?: NavigationType})
Creates a navigator. Creates a navigator.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| target | string | Yes | - | Path of the target page to be redirected to. | | target | string | Yes | - | Path of the target page to be redirected to. |
| type | NavigationType | No | NavigationType.Push | Navigation type. | | type | NavigationType | No | NavigationType.Push | Navigation type. |
- NavigationType enums - NavigationType enums
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | -------- |
| Push | Navigates to a specified page in the application. | | Push | Navigates to a specified page in the application. |
| Replace | Replaces the current page with another one in the application and destroys the current page. | | Replace | Replaces the current page with another one in the application and destroys the current page. |
| Back | Returns to the previous page or a specified page. | | Back | Returns to the previous page or a specified page. |
## Attributes ## Attributes
| Name | Parameters | Default Value | Description | | Name | Parameters | Default Value | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| active | boolean | - | Whether the **&lt;Navigator&gt;** component is activated. If the component is activated, the corresponding navigation takes effect. | | active | boolean | - | Whether the **\<Navigator>** component is activated. If the component is activated, the corresponding navigation takes effect. |
| params | Object | undefined | Data that needs to be passed to the target page during redirection. You can use **router.getParams()** to obtain the data on the target page. | | params | Object | undefined | Data that needs to be passed to the target page during redirection. You can use **router.getParams()** to obtain the data on the target page. |
## Example ## Example
``` ```ts
// Navigator Page // Navigator.ets
@Entry @Entry
@Component @Component
struct NavigatorExample { struct NavigatorExample {
@State active: boolean = false @State active: boolean = false
@State Text: string = 'news' @State Text: object = {name: 'news'}
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) { Navigator({ target: 'pages/container/navigator/Detail', type: NavigationType.Push }) {
Text('Go to ' + this.Text + ' page').width('100%').textAlign(TextAlign.Center) Text('Go to ' + this.Text['name'] + ' page')
.width('100%').textAlign(TextAlign.Center)
}.params({ text: this.Text }) }.params({ text: this.Text })
Navigator() { Navigator() {
...@@ -74,15 +76,15 @@ struct NavigatorExample { ...@@ -74,15 +76,15 @@ struct NavigatorExample {
} }
``` ```
``` ```ts
// Detail Page // Detail.ets
import router from '@system.router' import router from '@system.router'
@Entry @Entry
@Component @Component
struct DetailExample { struct DetailExample {
@State text: string = router.getParams().text @State text: any = router.getParams().text
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Start, justifyContent: FlexAlign.SpaceBetween }) {
...@@ -90,7 +92,8 @@ struct DetailExample { ...@@ -90,7 +92,8 @@ struct DetailExample {
Text('Go to back page').width('100%').height(20) Text('Go to back page').width('100%').height(20)
} }
Text('This is ' + this.text + ' page').width('100%').textAlign(TextAlign.Center) Text('This is ' + this.text['name'] + ' page')
.width('100%').textAlign(TextAlign.Center)
} }
.width('100%').height(200).padding({ left: 35, right: 35, top: 35 }) .width('100%').height(200).padding({ left: 35, right: 35, top: 35 })
} }
...@@ -98,9 +101,8 @@ struct DetailExample { ...@@ -98,9 +101,8 @@ struct DetailExample {
``` ```
```ts
``` // Back.ets
// Back Page
@Entry @Entry
@Component @Component
struct BackExample { struct BackExample {
......
...@@ -16,51 +16,53 @@ None ...@@ -16,51 +16,53 @@ None
Use the following attributes to bind gesture recognition to a component. When a gesture is recognized, the event callback is invoked to notify the component. Use the following attributes to bind gesture recognition to a component. When a gesture is recognized, the event callback is invoked to notify the component.
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| gesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to recognize.<br/>**gesture** specifies the type of the gesture to bind, and **mask** specifies the event response setting. | | gesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to recognize.<br/>- **gesture**: type of the gesture to bind.<br/>- **mask**: event response setting. |
| priorityGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to preferentially recognize.<br/>**gesture** specifies the type of the gesture to bind, and **mask** specifies the event response setting.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> - By default, the child component takes precedence over the parent component in gesture recognition. When **priorityGesture** is configured for the parent component, the parent component takes precedence over the child component in gesture recognition. | | priorityGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture to preferentially recognize.<br/>- **gesture**: type of the gesture to bind.<br/>- **mask**: event response setting.<br/>By default, the child component takes precedence over the parent component in gesture recognition. When **priorityGesture** is configured for the parent component, the parent component takes precedence over the child component in gesture recognition. |
| parallelGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture that can be triggered together with the child component gesture.<br/>**gesture** specifies the type of the gesture to bind, and **mask** specifies the event response setting.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> - The gesture event is not a bubbling event. When **parallelGesture** is set for the parent component, gesture events that are the same for the parent component and child components can be triggered, thereby implementing a bubbling effect. | | parallelGesture | gesture: GestureType,<br/>mask?: GestureMask | gesture: -,<br/>mask: GestureMask.Normal | Gesture that can be triggered together with the child component gesture.<br/>- **gesture**: type of the gesture to bind.<br/>- **mask**: event response setting.<br/>The gesture event is not a bubbling event. When **parallelGesture** is set for the parent component, gesture events bound to both the parent and child components can be triggered, thereby implementing a bubbling effect. |
- GestureMask enums - GestureMask enums
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | -------- |
| Normal | The gestures of child components are not masked and are recognized based on the default gesture recognition sequence. | | Normal | The gestures of child components are not masked and are recognized based on the default gesture recognition sequence. |
| IgnoreInternal | The gestures of child components are masked. Only the gestures of the current component are recognized.<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> However, the built-in gestures of the child components are not masked. For example, when the child component is a **&lt;List&gt;** component, the built-in sliding gestures can still be triggered. | | IgnoreInternal | The gestures of child components are masked. Only the gestures of the current component are recognized.<br/>However, the built-in gestures of the child components are not masked. For example, when the child component is a **&lt;List&gt;** component, the built-in sliding gestures can still be triggered. |
- Gesture types - GestureType enums
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | -------- |
| TapGesture | Tap gesture, which can be a single-tap or multi-tap gesture. | | TapGesture | Tap gesture, which can be a single-tap or multi-tap gesture. |
| LongPressGesture | Long press gesture. | | LongPressGesture | Long press gesture. |
| PanGesture | Pan gesture. | | PanGesture | Pan gesture. |
| PinchGesture | Pinch gesture. | | PinchGesture | Pinch gesture. |
| RotationGesture | Rotation gesture. | | RotationGesture | Rotation gesture. |
| GestureGroup | A group of gestures. Continuous recognition, parallel recognition, and exclusive recognition are supported. | | SwipeGesture | Swipe gesture, which can be idenfied when the swipe speed is 100 vp/s or higher. |
| GestureGroup | A group of gestures. Continuous recognition, parallel recognition, and exclusive recognition are supported. |
## Gesture Response Event ## Gesture Response Event
The component uses the **gesture** method to bind the gesture object and uses the events provided in this object to respond to the gesture operation. For example, the **onAction** event of the **TapGesture** object can be used to respond to a click event. For details about the event definition, see the section of each gesture object. A component uses the **gesture** method to bind the gesture object and uses the events provided in this object to respond to the gesture operation. For example, the **onAction** event of the **TapGesture** object can be used to respond to a click event. For details about the event definition, see the section of each gesture object.
- TapGesture events - TapGesture events
| Name | Description | | Name | Description |
| -------- | -------- | | -------- | -------- |
| onAction((event?: GestureEvent) =&gt; void) | Callback invoked when a tap gesture is recognized. | | onAction((event?: GestureEvent) =&gt; void) | Callback invoked when a tap gesture is recognized. |
- GestureEvent attributes - GestureEvent attributes
| Name | Type | Description | | Name | Type | Description |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| timestamp | number | Timestamp of the event. | | timestamp | number | Timestamp of the event. |
| target<sup>8+</sup> | EventTarget | Object that triggers the gesture event. | | target<sup>8+</sup> | [EventTarget](ts-universal-events-click.md) | Object that triggers the gesture event. |
## Example ## Example
```ts ```ts
// xxx.ets
@Entry @Entry
@Component @Component
struct GestureSettingsExample { struct GestureSettingsExample {
......
# Motion Path Animation # Motion Path Animation
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
>
> This animation is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version. > This animation is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
The attributes described in this topic are used to set the motion path of the component in a translation animation. The attributes below can be used to set the motion path of the component in a translation animation.
## Attributes ## Attributes
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| motionPath | {<br/>path: string,<br/>from?: number,<br/>to?: number,<br/>rotatable?: boolean<br/>}<br/>> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>> In a path, **start** and **end** can be used to replace the start point and end point. Example:<br/>> <br/>> 'Mstart.x start.y L50 50 Lend.x end.y Z' | {<br/>"",<br/>0.0,<br/>1.0,<br/>false<br/>} | Motion path of the component. The input parameters are described as follows:<br/>- **path**: motion path of the translation animation. The **svg** path string is used.<br/>- **from**: start point of the motion path. The default value is **0.0**.<br/>- **to**: end point of the motion path. The default value is **1.0**.<br/>- **rotatable**: whether to rotate along the path. | | motionPath | {<br/>path: string,<br/>from?: number,<br/>to?: number,<br/>rotatable?: boolean<br/>}<br/>**NOTE**<br/>In a path, **start** and **end** can be used to replace the start point and end point. Example:<br/>'Mstart.x start.y L50 50 Lend.x end.y Z' | {<br/>"",<br/>0.0,<br/>1.0,<br/>false<br/>} | Motion path of the component. The input parameters are described as follows:<br/>- **path**: motion path of the translation animation. The **svg** path string is used.<br/>- **from**: start point of the motion path. The default value is **0.0**.<br/>- **to**: end point of the motion path. The default value is **1.0**.<br/>- **rotatable**: whether to rotate along the path. |
## Example ## Example
``` ```
@Entry @Entry
@Component @Component
......
# Component ID # Component ID
**id** identifies a component uniquely within an application. This module provides APIs for obtaining the attributes of or sending events to the component with the specified ID.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** > **NOTE**
> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. >
> - The APIs of this module are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
> - The APIs provided by this module are system APIs.
## Required Permissions ## Required Permissions
...@@ -12,9 +15,9 @@ None ...@@ -12,9 +15,9 @@ None
## Attributes ## Attributes
| Name | Type | Default Value | Description | | Name | Type | Default Value | Description |
| -------- | -------- | -------- | -------- | | ---- | ------ | ---- | ------------------ |
| id | string | '' | Unique ID of the component. The uniqueness is ensured by the user. | | id | string | '' | Unique ID you assigned to the component.|
## APIs ## APIs
...@@ -27,15 +30,26 @@ getInspectorByKey(id: string): string ...@@ -27,15 +30,26 @@ getInspectorByKey(id: string): string
Obtains all attributes of the component with the specified ID, excluding the information about child components. Obtains all attributes of the component with the specified ID, excluding the information about child components.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | ---- | ------ | ---- | ---- | ----------- |
| id | string | Yes | - | ID of the component whose attributes are to be obtained. | | id | string | Yes | - | ID of the component whose attributes are to be obtained.|
- Return value - Return value
| Type | Description | | Type | Description |
| -------- | -------- | | ------ | --------------- |
| string | JSON string of the component attribute list. | | string | JSON string of the component attribute list.|
### getInspectorTree
getInspectorTree(): string
Obtains the component tree and component attributes.
- Return value
| Type | Description |
| ------ | ------------------- |
| string | JSON string of the component tree and component attribute list.|
### sendEventByKey ### sendEventByKey
...@@ -44,61 +58,207 @@ sendEventByKey(id: string, action: number, params: string): boolean ...@@ -44,61 +58,207 @@ sendEventByKey(id: string, action: number, params: string): boolean
Sends an event to the component with the specified ID. Sends an event to the component with the specified ID.
- Parameters - Parameters
| Name | Type | Mandatory | Default Value | Description | | Name | Type | Mandatory | Default Value | Description |
| -------- | -------- | -------- | -------- | -------- | | ------ | ------ | ---- | ---- | ---------------------------------------- |
| id | string | Yes | - | ID of the component for which the event is to be sent. | | id | string | Yes | - | ID of the component to which the event is to be sent. |
| action | number | Yes | - | Type of the event to be sent. The options are as follows:<br/>- Click event: 10.<br/>- LongClick: 11. | | action | number | Yes | - | Type of the event to be sent. The options are as follows:<br>- **10**: click event.<br>- **11**: long click event.|
| params | string | Yes | - | Event parameters. If there is no parameter, pass an empty string **""**. | | params | string | Yes | - | Event parameters. If there is no parameter, pass an empty string **""**. |
- Return value
| Type | Description |
| ------- | ------------------------------ |
| boolean | Returns **true** if the component with the specified ID is found; returns **false** otherwise.|
### sendTouchEvent
sendTouchEvent(event: TouchObject): boolean
Sends a touch event.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ----- | ----------- | ---- | ---- | ---------------------------------------- |
| event | TouchObject | Yes | - | Location where a touch event is triggered. For details, see [TouchEvent](ts-universal-events-touch.md#touchevent).|
- Return value
| Type | Description |
| ------- | -------------------------- |
| boolean | Returns **true** if the event is sent successfully; returns **false** otherwise.|
### sendKeyEvent
sendKeyEvent(event: KeyEvent): boolean
Sends a key event.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ----- | -------- | ---- | ---- | ---------------------------------------- |
| event | KeyEvent | Yes | - | Key event. For details, see [KeyEvent](ts-universal-events-key.md#keyevent).|
- Return value
| Type | Description |
| ------- | --------------------------- |
| boolean | Returns **true** if the event is sent successfully; returns **false** otherwise.|
### sendMouseEvent
sendMouseEvent(event: MouseEvent): boolean
Sends a mouse event.
- Parameters
| Name | Type | Mandatory | Default Value | Description |
| ----- | ---------- | ---- | ---- | ---------------------------------------- |
| event | MouseEvent | Yes | - | Mouse event. For details, see [MouseEvent](ts-universal-mouse-key.md#mouseevent).|
- Return value - Return value
| Type | Description |
| -------- | -------- |
| boolean | Returns **false** if the component with the specified ID cannot be found; returns **true** otherwise. |
| Type | Description |
| ------- | --------------------------- |
| boolean | Returns **true** if the event is sent successfully; returns **false** otherwise.|
## Example ## Example
```ts
``` // xxx.ets
class Utils {
static rect_left;
static rect_top;
static rect_right;
static rect_bottom;
static rect_value;
static getComponentRect(key) {
let strJson = getInspectorByKey(key);
let obj = JSON.parse(strJson);
console.info("[getInspectorByKey] current component obj is: " + JSON.stringify(obj));
let rectInfo = JSON.parse('[' + obj.$rect + ']')
console.info("[getInspectorByKey] rectInfo is: " + rectInfo);
this.rect_left = JSON.parse('[' + rectInfo[0] + ']')[0]
this.rect_top = JSON.parse('[' + rectInfo[0] + ']')[1]
this.rect_right = JSON.parse('[' + rectInfo[1] + ']')[0]
this.rect_bottom = JSON.parse('[' + rectInfo[1] + ']')[1]
return this.rect_value = {
"left": this.rect_left, "top": this.rect_top, "right": this.rect_right, "bottom": this.rect_bottom
}
}
}
@Entry @Entry
@Component @Component
struct IdExample { struct IdExample {
@State text: string = ''
build() { build() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
Button() { Button() {
Text('click') Text('onKeyTab').fontSize(25).fontWeight(FontWeight.Bold)
.fontSize(25) }.margin({ top: 20 }).backgroundColor('#0D9FFB')
.fontWeight(FontWeight.Bold) .onKeyEvent(() => {
} this.text = "onKeyTab"
.type(ButtonType.Capsule) })
.margin({
top: 20 Button() {
}).onClick(() => { Text('click to start').fontSize(25).fontWeight(FontWeight.Bold)
}.margin({ top: 20 })
.onClick(() => {
console.info(getInspectorByKey("click")) console.info(getInspectorByKey("click"))
console.info(getInspectorTree()) console.info(getInspectorTree())
this.text = "Button 'click to start' is clicked"
setTimeout(() => { setTimeout(() => {
sendEventByKey("longclick", 11, "") sendEventByKey("longclick", 11, "")
}, 2000) }, 2000)
}).id('click') }).id('click')
Button() { Button() {
Text('longclick') Text('longclick').fontSize(25).fontWeight(FontWeight.Bold)
.fontSize(25) }.margin({ top: 20 }).backgroundColor('#0D9FFB')
.fontWeight(FontWeight.Bold)
}
.type(ButtonType.Capsule)
.margin({
top: 20
})
.backgroundColor('#0D9FFB')
.gesture( .gesture(
LongPressGesture().onActionEnd(() => { LongPressGesture().onActionEnd(() => {
console.info('long clicked') console.info('long clicked')
})) this.text = "Button 'longclick' is longclicked"
.id('longclick') setTimeout(() => {
let rect = Utils.getComponentRect('onTouch')
let touchPoint: TouchObject = {
id: 1,
x: rect.left + (rect.right - rect.left) / 2,
y: rect.top + (rect.bottom - rect.top) / 2,
type: TouchType.Down,
screenX: rect.left + (rect.right - rect.left) / 2,
screenY: rect.left + (rect.right - rect.left) / 2,
}
sendTouchEvent(touchPoint)
touchPoint.type = TouchType.Up
sendTouchEvent(touchPoint)
}, 2000)
})).id('longclick')
Button() {
Text('onTouch').fontSize(25).fontWeight(FontWeight.Bold)
}.type(ButtonType.Capsule).margin({ top: 20 })
.onClick(() => {
console.info('onTouch is clicked')
this.text = "Button 'onTouch' is clicked"
setTimeout(() => {
let rect = Utils.getComponentRect('onMouse')
let mouseEvent: MouseEvent = {
button: MouseButton.Left,
action: MouseAction.Press,
x: rect.left + (rect.right - rect.left) / 2,
y: rect.top + (rect.bottom - rect.top) / 2,
screenX: rect.left + (rect.right - rect.left) / 2,
screenY: rect.top + (rect.bottom - rect.top) / 2,
timestamp: 1,
target: {
area: {
width: 1,
height: 1,
position: {
x: 1,
y: 1
},
globalPosition: {
x: 1,
y: 1
}
}
},
source: SourceType.Mouse
}
sendMouseEvent(mouseEvent)
}, 2000)
}).id('onTouch')
Button() {
Text('onMouse').fontSize(25).fontWeight(FontWeight.Bold)
}.margin({ top: 20 }).backgroundColor('#0D9FFB')
.onMouse(() => {
console.info('onMouse')
this.text = "Button 'onMouse' in onMouse"
setTimeout(() => {
let keyEvent: KeyEvent = {
type: KeyType.Down,
keyCode: 2049,
keyText: 'tab',
keySource: 4,
deviceId: 0,
metaKey: 0,
timestamp: 0
}
sendKeyEvent(keyEvent)
}, 2000)
}).id('onMouse')
Text(this.text).fontSize(25).padding(15)
} }
.width('100%') .width('100%').height('100%')
.height('100%')
} }
} }
``` ```
...@@ -6,9 +6,9 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri ...@@ -6,9 +6,9 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri
## Development<a name="section13857170163412"></a> ## Development<a name="section13857170163412"></a>
1. Complete the operations described in [Getting Started with Hi3861](../quick-start/quickstart-lite-introduction-hi3861.md#section19352114194115). 1. Complete the operations described in [Getting Started with Hi3861](../quick-start/quickstart-lite-overview.md).
LED control examples are stored in the file **applications/sample/wifi-iot/app/iothardware/led\_example.c**. LED control examples are stored in the file **applications/sample/wifi-iot/app/iothardware/led\_example.c**.
2. Understand the cable connections by referring to the schematic diagram. You can learn that LED of hispark pegasus is connected to pin 9 of the chip. 2. Understand the cable connections by referring to the schematic diagram. You can learn that LED of hispark pegasus is connected to pin 9 of the chip.
...@@ -73,17 +73,16 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri ...@@ -73,17 +73,16 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri
break; break;
} }
} }
return NULL;
} }
``` ```
5. Call **SYS\_RUN\(\)** of OpenHarmony to start the service. \(**SYS\_RUN** is defined in the **ohos\_init.h** file.\) 5. Call **SYS\_RUN\(\)** of OpenHarmony to start the service. \(**SYS\_RUN** is defined in the **ohos\_init.h** file.\)
``` ```
SYS_RUN(LedExampleEntry); SYS_RUN(LedExampleEntry);
``` ```
6. Change the **applications/sample/wifi-iot/app/BUILD.gn** file to enable **led\_example.c** to participate in compilation. 6. Change the **applications/sample/wifi-iot/app/BUILD.gn** file to enable **led\_example.c** to participate in compilation.
``` ```
import("//build/lite/config/component/lite_component.gni") import("//build/lite/config/component/lite_component.gni")
...@@ -97,10 +96,10 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri ...@@ -97,10 +96,10 @@ Based on the Hi3861 platform, the OpenHarmony WLAN module provides abundant peri
## Verification<a name="section1949121910344"></a> ## Verification<a name="section1949121910344"></a>
For details about the compilation and burning processes, see [Building](../quick-start/quickstart-lite-steps-hi3861-building.md) and [Burning](../quick-start/quickstart-lite-steps-hi3861-burn.md) in the _Getting Started with Hi3861_. For details about the compilation and burning processes, see [Building](../quick-start/quickstart-lite-steps-hi3861-building.md) and [Burning](../quick-start/quickstart-lite-steps-hi3861-burn.md).
After the preceding two steps are complete, press the **RST** button to reset the module. If the LED blinks periodically as expected, the verification is passed. After the preceding two steps are complete, press the **RST** button to reset the module. If the LED blinks periodically as expected, the verification is passed.
**Figure 1** LED blinking<a name="fig20768175218527"></a> **Figure 1** LED blinking<a name="fig20768175218527"></a>
![](figures/led-blinking.gif "led-blinking") ![](figures/led-blinking.gif "led-blinking")
...@@ -44,26 +44,26 @@ import stats from '@ohos.bundleState'; ...@@ -44,26 +44,26 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryBundleActiveStates(0, 20000000000000).then( res => { stats.queryBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryBundleActiveStates(0, 20000000000000, (err, res) => { stats.queryBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -74,30 +74,30 @@ import stats from '@ohos.bundleState'; ...@@ -74,30 +74,30 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryBundleStateInfos(0, 20000000000000).then( res => { stats.queryBundleStateInfos(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1; let i = 1;
for(let key in res){ for (let key in res) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++; i++;
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryBundleStateInfos(0, 20000000000000, (err, res) => { stats.queryBundleStateInfos(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.');
let i = 1; let i = 1;
for(let key in res){ for (let key in res) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key]));
i++; i++;
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -108,26 +108,26 @@ import stats from '@ohos.bundleState'; ...@@ -108,26 +108,26 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryCurrentBundleActiveStates(0, 20000000000000).then( res => { stats.queryCurrentBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => { stats.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -138,26 +138,26 @@ import stats from '@ohos.bundleState'; ...@@ -138,26 +138,26 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => { stats.queryBundleStateInfoByInterval(0, 0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => { stats.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -168,18 +168,18 @@ import stats from '@ohos.bundleState'; ...@@ -168,18 +168,18 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.queryAppUsagePriorityGroup().then( res => { stats.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.queryAppUsagePriorityGroup((err, res) => { stats.queryAppUsagePriorityGroup((err, res) => {
if(err.code === 0) { if (err) {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} }
}); });
``` ```
...@@ -190,18 +190,18 @@ import stats from '@ohos.bundleState'; ...@@ -190,18 +190,18 @@ import stats from '@ohos.bundleState';
import stats from '@ohos.bundleState' import stats from '@ohos.bundleState'
// 异步方法promise方式 // 异步方法promise方式
stats.isIdleState("com.ohos.camera").then( res => { stats.isIdleState("com.ohos.camera").then(res => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
}); });
// 异步方法callback方式 // 异步方法callback方式
stats.isIdleState("com.ohos.camera", (err, res) => { stats.isIdleState("com.ohos.camera", (err, res) => {
if(err.code === 0) { if (err) {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code); console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} }
}); });
``` ```
\ No newline at end of file
...@@ -3,9 +3,13 @@ ...@@ -3,9 +3,13 @@
## 场景介绍 ## 场景介绍
使用坐标描述一个位置,非常准确,但是并不直观,面向用户表达并不友好。 使用坐标描述一个位置,非常准确,但是并不直观,面向用户表达并不友好。系统向开发者提供了以下两种转化能力。
系统向开发者提供了地理编码转化能力(将地理描述转化为具体坐标),以及逆地理编码转化能力(将坐标转化为地理描述)。其中地理编码包含多个属性来描述位置,包括国家、行政区划、街道、门牌号、地址描述等等,这样的信息更便于用户理解。 - 地理编码转化:将地理描述转化为具体坐标。
- 逆地理编码转化能力:将坐标转化为地理描述。
其中地理编码包含多个属性来描述位置,包括国家、行政区划、街道、门牌号、地址描述等等,这样的信息更便于用户理解。
## 接口说明 ## 接口说明
......
# 传感器开发概述 # 传感器开发概述
OpenHarmony系统传感器是应用访问底层硬件传感器的一种设备抽象概念。开发者根据传感器提供的Sensor API,可以查询设备上的传感器,订阅传感器数据,并根据传感器数据定制相应的算法开发各类应用,比如指南针、运动健康、游戏等。 OpenHarmony系统传感器是应用访问底层硬件传感器的一种设备抽象概念。开发者根据传感器提供的[Sensor接口](../reference/apis/js-apis-sensor.md),可以查询设备上的传感器,订阅传感器数据,并根据传感器数据定制相应的算法开发各类应用,比如指南针、运动健康、游戏等。
传感器是指用于侦测环境中所发生事件或变化,并将此消息发送至其他电子设备(如中央处理器)的设备,通常由敏感组件和转换组件组成。传感器是实现物联网智能化的重要基石,为实现全场景智慧化战略,支撑“1+8+N”产品需求,需要构筑统一的传感器管理框架,达到为各产品/业务提供低时延、低功耗的感知数据的目的。下面为传感器列表: 传感器是指用于侦测环境中所发生事件或变化,并将此消息发送至其他电子设备(如中央处理器)的设备,通常由敏感组件和转换组件组成。传感器是实现物联网智能化的重要基石,为实现全场景智慧化战略,支撑“1+8+N”产品需求,需要构筑统一的传感器管理框架,达到为各产品/业务提供低时延、低功耗的感知数据的目的。下面为传感器列表:
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
当设备需要设置不同的振动效果时,可以调用Vibrator模块,例如:设备的按键可以设置不同强度和不同时长的振动,闹钟和来电可以设置不同强度和时长的单次或周期振动。 当设备需要设置不同的振动效果时,可以调用Vibrator模块,例如:设备的按键可以设置不同强度和不同时长的振动,闹钟和来电可以设置不同强度和时长的单次或周期振动。
详细的接口介绍请参考[Vibrator接口](../reference/apis/js-apis-vibrator.md)
## 接口说明 ## 接口说明
......
...@@ -12,18 +12,19 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -12,18 +12,19 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | getSystemLanguage():&nbsp;string | 获取系统语言。 | | ohos.i18n | getSystemLanguage():string | 获取系统语言。 |
| ohos.i18n | getSystemRegion():&nbsp;string | 获取系统区域。 | | ohos.i18n | getSystemRegion():string | 获取系统区域。 |
| ohos.i18n | getSystemLocale():&nbsp;string | 获取系统Locale。 | | ohos.i18n | getSystemLocale():string | 获取系统Locale。 |
| ohos.i18n | isRTL(locale:&nbsp;string):&nbsp;boolean<sup>7+</sup> | locale对应的语言是否为从右到左语言。 | | ohos.i18n | isRTL(locale:string):boolean<sup>7+</sup> | locale对应的语言是否为从右到左语言。 |
| ohos.i18n | is24HourClock():&nbsp;boolean<sup>7+</sup> | 获取当前系统时间是否采用24小时制 | | ohos.i18n | is24HourClock():boolean<sup>7+</sup> | 获取当前系统时间是否采用24小时制。 |
| ohos.i18n | getDisplayLanguage(language:&nbsp;string,&nbsp;locale:&nbsp;string,&nbsp;sentenceCase?:&nbsp;boolean):&nbsp;string | 获取语言的本地化表示。 | | ohos.i18n | getDisplayLanguage(language:string,locale:string,sentenceCase?:boolean):string | 获取语言的本地化表示。 |
| ohos.i18n | getDisplayCountry(country:&nbsp;string,&nbsp;locale:&nbsp;string,&nbsp;sentenceCase?:&nbsp;boolean):&nbsp;string | 获取国家的本地化表示。 | | ohos.i18n | getDisplayCountry(country:string,locale:string,sentenceCase?:boolean):string | 获取国家的本地化表示。 |
### 开发步骤 ### 开发步骤
1. 获取系统语言 1. 获取系统语言。
调用getSystemLanguage方法获取当前系统设置的语言(i18n为导入的模块)。 调用getSystemLanguage方法获取当前系统设置的语言(i18n为导入的模块)。
...@@ -31,21 +32,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -31,21 +32,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var language = i18n.getSystemLanguage(); var language = i18n.getSystemLanguage();
``` ```
2. 获取系统区域 2. 获取系统区域。
调用getSystemRegion方法获取当前系统设置的区域 调用getSystemRegion方法获取当前系统设置的区域
``` ```
var region = i18n.getSystemRegion(); var region = i18n.getSystemRegion();
``` ```
3. 获取系统Locale 3. 获取系统Locale。
调用getSystemLocale方法获取当前系统设置的Locale 调用getSystemLocale方法获取当前系统设置的Locale
``` ```
var locale = i18n.getSystemLocale(); var locale = i18n.getSystemLocale();
``` ```
4. 判断Locale的语言是否为RTL语言 4. 判断Locale的语言是否为RTL语言。
调用isRTL方法获取Locale的语言是否为从右到左语言。 调用isRTL方法获取Locale的语言是否为从右到左语言。
...@@ -53,14 +57,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -53,14 +57,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var rtl = i18n.isRTL("zh-CN"); var rtl = i18n.isRTL("zh-CN");
``` ```
5. 判断当前系统时间是否采用24小时制 5. 判断当前系统时间是否采用24小时制。
调用is24HourClock方法来判断当前系统的时间是否采用24小时制。 调用is24HourClock方法来判断当前系统的时间是否采用24小时制。
``` ```
var hourClock = i18n.is24HourClock(); var hourClock = i18n.is24HourClock();
``` ```
6. 获取语言的本地化表示 6. 获取语言的本地化表示。
调用getDisplayLanguage方法获取某一语言的本地化表示。其中,language表示待本地化显示的语言,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。 调用getDisplayLanguage方法获取某一语言的本地化表示。其中,language表示待本地化显示的语言,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。
``` ```
...@@ -70,7 +76,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -70,7 +76,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase); var localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase);
``` ```
7. 获取国家的本地化表示 7. 获取国家的本地化表示。
调用getDisplayCountry方法获取某一国家的本地化表示。其中,country表示待本地化显示的国家,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。 调用getDisplayCountry方法获取某一国家的本地化表示。其中,country表示待本地化显示的国家,locale表示本地化的Locale,sentenceCase结果是否需要首字母大写。
``` ```
...@@ -90,23 +97,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -90,23 +97,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | getCalendar(locale:&nbsp;string,&nbsp;type?:&nbsp;string):&nbsp;Calendar<sup>8+</sup> | 获取指定locale和type的日历对象。 | | ohos.i18n | getCalendar(locale:string,type?:string):Calendar<sup>8+</sup> | 获取指定locale和type的日历对象。 |
| ohos.i18n | setTime(date:&nbsp;Date): void<sup>8+</sup> | 设置日历对象内部的时间日期。 | | ohos.i18n | setTime(date:Date): void<sup>8+</sup> | 设置日历对象内部的时间日期。 |
| ohos.i18n | setTime(time:&nbsp;number): void<sup>8+</sup> | 设置日历对象内部的时间日期。 | | ohos.i18n | setTime(time:number): void<sup>8+</sup> | 设置日历对象内部的时间日期。 |
| ohos.i18n | set(year:&nbsp;number,&nbsp;month:&nbsp;number,&nbsp;date:&nbsp;number,&nbsp;hour?:&nbsp;number,&nbsp;minute?:&nbsp;number,&nbsp;second?:&nbsp;number): void<sup>8+</sup> | 设置日历对象的年、月、日、时、分、秒。 | | ohos.i18n | set(year:number,month:number,date:number,hour?:number,minute?:number,second?:number): void<sup>8+</sup> | 设置日历对象的年、月、日、时、分、秒。 |
| ohos.i18n | setTimeZone(timezone:&nbsp;string): void<sup>8+</sup> | 设置日历对象的时区。 | | ohos.i18n | setTimeZone(timezone:string): void<sup>8+</sup> | 设置日历对象的时区。 |
| ohos.i18n | getTimeZone():&nbsp;string<sup>8+</sup> | 获取日历对象的时区。 | | ohos.i18n | getTimeZone():string<sup>8+</sup> | 获取日历对象的时区。 |
| ohos.i18n | getFirstDayOfWeek():&nbsp;number<sup>8+</sup> | 获取日历对象的一周起始日。 | | ohos.i18n | getFirstDayOfWeek():number<sup>8+</sup> | 获取日历对象的一周起始日。 |
| ohos.i18n | setFirstDayOfWeek(value:&nbsp;number): void<sup>8+</sup> | 设置日历对象的一周起始日。 | | ohos.i18n | setFirstDayOfWeek(value:number): void<sup>8+</sup> | 设置日历对象的一周起始日。 |
| ohos.i18n | getMinimalDaysInFirstWeek():&nbsp;number<sup>8+</sup> | 获取一年中第一周的最小天数。 | | ohos.i18n | getMinimalDaysInFirstWeek():number<sup>8+</sup> | 获取一年中第一周的最小天数。 |
| ohos.i18n | setMinimalDaysInFirstWeek(value:&nbsp;number): void<sup>8+</sup> | 设置一年中第一周的最小天数。 | | ohos.i18n | setMinimalDaysInFirstWeek(value:number): void<sup>8+</sup> | 设置一年中第一周的最小天数。 |
| ohos.i18n | getDisplayName(locale:&nbsp;string):&nbsp;string<sup>8+</sup> | 获取日历对象的本地化表示。 | | ohos.i18n | getDisplayName(locale:string):string<sup>8+</sup> | 获取日历对象的本地化表示。 |
| ohos.i18n | isWeekend(date?:&nbsp;Date):&nbsp;boolean<sup>8+</sup> | 判断给定的日期是否在日历中是周末。 | | ohos.i18n | isWeekend(date?:Date):boolean<sup>8+</sup> | 判断给定的日期是否在日历中是周末。 |
### 开发步骤 ### 开发步骤
1. 实例化日历对象 1. 实例化日历对象。
调用getCalendar方法获取指定locale和type的时区对象(i18n为导入的模块)。其中,type表示合法的日历类型,目前合法的日历类型包括:"buddhist", "chinese", "coptic", "ethiopic", "hebrew", "gregory", "indian", "islamic_civil", "islamic_tbla", "islamic_umalqura", "japanese", "persian"。当type没有给出时,采用区域默认的日历类型。 调用getCalendar方法获取指定locale和type的时区对象(i18n为导入的模块)。其中,type表示合法的日历类型,目前合法的日历类型包括:"buddhist", "chinese", "coptic", "ethiopic", "hebrew", "gregory", "indian", "islamic_civil", "islamic_tbla", "islamic_umalqura", "japanese", "persian"。当type没有给出时,采用区域默认的日历类型。
...@@ -114,7 +122,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -114,7 +122,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var calendar = i18n.getCalendar("zh-CN", "gregory); var calendar = i18n.getCalendar("zh-CN", "gregory);
``` ```
2. 设置日历对象的时间 2. 设置日历对象的时间。
调用setTime方法设置日历对象的时间。setTime方法接收两种类型的参数。一种是传入一个Date对象,另一种是传入一个数值表示从1970.1.1 00:00:00 GMT逝去的毫秒数。 调用setTime方法设置日历对象的时间。setTime方法接收两种类型的参数。一种是传入一个Date对象,另一种是传入一个数值表示从1970.1.1 00:00:00 GMT逝去的毫秒数。
``` ```
...@@ -124,14 +133,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -124,14 +133,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
calendar.setTime(date2); calendar.setTime(date2);
``` ```
3. 设置日历对象的年、月、日、时、分、秒 3. 设置日历对象的年、月、日、时、分、秒。
调用set方法设置日历对象的年、月、日、时、分、秒。 调用set方法设置日历对象的年、月、日、时、分、秒。
``` ```
calendar.set(2021, 12, 21, 6, 0, 0) calendar.set(2021, 12, 21, 6, 0, 0)
``` ```
4. 设置、获取日历对象的时区 4. 设置、获取日历对象的时区。
调用setTimeZone方法和getTimeZone方法来设置、获取日历对象的时区。其中,setTimeZone方法需要传入一个字符串表示需要设置的时区。 调用setTimeZone方法和getTimeZone方法来设置、获取日历对象的时区。其中,setTimeZone方法需要传入一个字符串表示需要设置的时区。
...@@ -140,7 +151,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -140,7 +151,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var timezone = calendar.getTimeZone(); var timezone = calendar.getTimeZone();
``` ```
5. 设置、获取日历对象的一周起始日 5. 设置、获取日历对象的一周起始日。
调用setFirstDayOfWeek方法和getFirstDayOfWeek方法设置、获取日历对象的一周起始日。其中,setFirstDayOfWeek需要传入一个数值表示一周的起始日,1代表周日,7代表周六。 调用setFirstDayOfWeek方法和getFirstDayOfWeek方法设置、获取日历对象的一周起始日。其中,setFirstDayOfWeek需要传入一个数值表示一周的起始日,1代表周日,7代表周六。
...@@ -165,7 +177,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -165,7 +177,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var localizedName = calendar.getDisplayName("zh-CN"); var localizedName = calendar.getDisplayName("zh-CN");
``` ```
8. 判断某一个日期是否为周末 8. 判断某一个日期是否为周末。
调用isWeekend方法来判断输入的Date是否为周末。 调用isWeekend方法来判断输入的Date是否为周末。
...@@ -184,14 +197,15 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -184,14 +197,15 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | constructor(country:&nbsp;string,&nbsp;options?:&nbsp;PhoneNumberFormatOptions)<sup>8+</sup> | 实例化PhoneNumberFormat对象。 | | ohos.i18n | constructor(country:string,options?:PhoneNumberFormatOptions)<sup>8+</sup> | 实例化PhoneNumberFormat对象。 |
| ohos.i18n | isValidNumber(number:&nbsp;string):&nbsp;boolean<sup>8+</sup> | 判断number是否是一个格式正确的电话号码。 | | ohos.i18n | isValidNumber(number:string):boolean<sup>8+</sup> | 判断number是否是一个格式正确的电话号码。 |
| ohos.i18n | format(number:&nbsp;string):&nbsp;string<sup>8+</sup> | 对number按照指定国家及风格进行格式化。 | | ohos.i18n | format(number:string):string<sup>8+</sup> | 对number按照指定国家及风格进行格式化。 |
### 开发步骤 ### 开发步骤
1. 实例化电话号码格式化对象 1. 实例化电话号码格式化对象。
调用PhoneNumberFormat的构造函数来实例化电话号码格式化对象,需要传入电话号码的国家代码及格式化选项。其中,格式化选项是可选的,包括style选项,该选项的取值包括:"E164", "INTERNATIONAL", "NATIONAL", "RFC3966"。 调用PhoneNumberFormat的构造函数来实例化电话号码格式化对象,需要传入电话号码的国家代码及格式化选项。其中,格式化选项是可选的,包括style选项,该选项的取值包括:"E164", "INTERNATIONAL", "NATIONAL", "RFC3966"。
...@@ -199,14 +213,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -199,14 +213,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var phoneNumberFormat = new i18n.PhoneNubmerFormat("CN", {type: "E164"}); var phoneNumberFormat = new i18n.PhoneNubmerFormat("CN", {type: "E164"});
``` ```
2. 判断电话号码格式是否正确 2. 判断电话号码格式是否正确。
调用isValidNumber方法来判断输入的电话号码的格式是否正确。 调用isValidNumber方法来判断输入的电话号码的格式是否正确。
``` ```
var validNumber = phoneNumberFormat.isValidNumber("15812341234"); var validNumber = phoneNumberFormat.isValidNumber("15812341234");
``` ```
3. 电话号码格式化 3. 电话号码格式化。
调用电话号码格式化对象的format方法来对输入的电话号码进行格式化。 调用电话号码格式化对象的format方法来对输入的电话号码进行格式化。
``` ```
...@@ -223,12 +239,13 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -223,12 +239,13 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | unitConvert(fromUnit:&nbsp;UnitInfo,&nbsp;toUnit:&nbsp;UnitInfo,&nbsp;value:&nbsp;number,&nbsp;locale:&nbsp;string,&nbsp;style?:&nbsp;string):&nbsp;string<sup>8+</sup> | 将fromUnit的单位转换为toUnit的单位,并根据区域与风格进行格式化。 | | ohos.i18n | unitConvert(fromUnit:UnitInfo,toUnit:UnitInfo,value:number,locale:string,style?:string):string<sup>8+</sup> | 将fromUnit的单位转换为toUnit的单位,并根据区域与风格进行格式化。 |
### 开发步骤 ### 开发步骤
1. 度量衡单位转换 1. 度量衡单位转换。
调用[unitConvert](../reference/apis/js-apis-intl.md)方法实现度量衡单位转换,并进行格式化显示的功能。 调用[unitConvert](../reference/apis/js-apis-intl.md)方法实现度量衡单位转换,并进行格式化显示的功能。
...@@ -251,15 +268,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -251,15 +268,16 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | getInstance(locale?:&nbsp;string):&nbsp;IndexUtil<sup>8+</sup> | 实例化字母表索引对象。 | | ohos.i18n | getInstance(locale?:string):IndexUtil<sup>8+</sup> | 实例化字母表索引对象。 |
| ohos.i18n | getIndexList():&nbsp;Array&lt;string&gt;<sup>8+</sup> | 获取当前Locale的索引列表。 | | ohos.i18n | getIndexList():Array&lt;string&gt;<sup>8+</sup> | 获取当前Locale的索引列表。 |
| ohos.i18n | addLocale(locale:&nbsp;string): void<sup>8+</sup> | 将新的Locale对应的索引加入当前索引列表。 | | ohos.i18n | addLocale(locale:string): void<sup>8+</sup> | 将新的Locale对应的索引加入当前索引列表。 |
| ohos.i18n | getIndex(text:&nbsp;string):&nbsp;string<sup>8+</sup> | 获取text对应的索引。 | | ohos.i18n | getIndex(text:string):string<sup>8+</sup> | 获取text对应的索引。 |
### 开发步骤 ### 开发步骤
1. 实例化字母表索引对象 1. 实例化字母表索引对象。
调用getInstance方法来实例化特定locale对应的字母表索引对象。当locale参数为空时,实例化系统默认Locale的字母表索引对象。 调用getInstance方法来实例化特定locale对应的字母表索引对象。当locale参数为空时,实例化系统默认Locale的字母表索引对象。
...@@ -267,21 +285,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -267,21 +285,24 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var indexUtil = getInstance("zh-CN"); var indexUtil = getInstance("zh-CN");
``` ```
2. 获取索引列表 2. 获取索引列表。
调用getIndexList方法来获取当前Locale对应的字母表索引列表。 调用getIndexList方法来获取当前Locale对应的字母表索引列表。
``` ```
var indexList = indexUtil.getIndexList(); var indexList = indexUtil.getIndexList();
``` ```
3. 增加新的索引 3. 增加新的索引。
调用addLocale方法,将新的Locale对应的字母表索引添加到当前字母表索引列表中。 调用addLocale方法,将新的Locale对应的字母表索引添加到当前字母表索引列表中。
``` ```
indexUtil.addLocale("ar") indexUtil.addLocale("ar")
``` ```
4. 获取字符串对应的索引 4. 获取字符串对应的索引。
调用getIndex方法来获取某一字符串对应的字母表索引。 调用getIndex方法来获取某一字符串对应的字母表索引。
``` ```
...@@ -299,21 +320,22 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -299,21 +320,22 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| ohos.i18n | getLineInstance(locale:&nbsp;string):&nbsp;BreakIterator<sup>8+</sup> | 实例化断行对象。 | | ohos.i18n | getLineInstance(locale:string):BreakIterator<sup>8+</sup> | 实例化断行对象。 |
| ohos.i18n | setLineBreakText(text:&nbsp;string): void<sup>8+</sup> | 设置要处理的文本。 | | ohos.i18n | setLineBreakText(text:string): void<sup>8+</sup> | 设置要处理的文本。 |
| ohos.i18n | getLineBreakText():&nbsp;string<sup>8+</sup> | 获取要处理的文本。 | | ohos.i18n | getLineBreakText():string<sup>8+</sup> | 获取要处理的文本。 |
| ohos.i18n | current():&nbsp;number<sup>8+</sup> | 获取当前断行对象在处理文本的位置。 | | ohos.i18n | current():number<sup>8+</sup> | 获取当前断行对象在处理文本的位置。 |
| ohos.i18n | first():&nbsp;number<sup>8+</sup> | 将断行对象设置到第一个可断句的分割点。 | | ohos.i18n | first():number<sup>8+</sup> | 将断行对象设置到第一个可断句的分割点。 |
| ohos.i18n | last():&nbsp;number<sup>8+</sup> | 将断行对象设置到最后一个可断句的分割点。 | | ohos.i18n | last():number<sup>8+</sup> | 将断行对象设置到最后一个可断句的分割点。 |
| ohos.i18n | next(index?:&nbsp;number):&nbsp;number<sup>8+</sup> | 将断行对象移动index个分割点的位置。 | | ohos.i18n | next(index?:number):number<sup>8+</sup> | 将断行对象移动index个分割点的位置。 |
| ohos.i18n | previous():&nbsp;number<sup>8+</sup> | 将断行对象移动到前一个分割点的位置。 | | ohos.i18n | previous():number<sup>8+</sup> | 将断行对象移动到前一个分割点的位置。 |
| ohos.i18n | following(offset:&nbsp;number):&nbsp;number<sup>8+</sup> | 将断行对象移动到offset指定位置的后面一个分割点的位置。 | | ohos.i18n | following(offset:number):number<sup>8+</sup> | 将断行对象移动到offset指定位置的后面一个分割点的位置。 |
| ohos.i18n | isBoundary(offset:&nbsp;number):&nbsp;boolean<sup>8+</sup> | 判断某个位置是否是分割点。 | | ohos.i18n | isBoundary(offset:number):boolean<sup>8+</sup> | 判断某个位置是否是分割点。 |
### 开发步骤 ### 开发步骤
1. 实例化断行对象 1. 实例化断行对象。
调用getLineInstance方法来实例化断行对象。 调用getLineInstance方法来实例化断行对象。
...@@ -322,7 +344,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -322,7 +344,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var breakIterator = i18n.getLineInstance(locale); var breakIterator = i18n.getLineInstance(locale);
``` ```
2. 设置、访问要断行处理的文本 2. 设置、访问要断行处理的文本。
调用setLineBreakText方法和getLineBreakText方法来设置、访问要断行处理的文本。 调用setLineBreakText方法和getLineBreakText方法来设置、访问要断行处理的文本。
...@@ -332,7 +355,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -332,7 +355,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var breakText = breakIterator.getLineBreakText(); var breakText = breakIterator.getLineBreakText();
``` ```
3. 获取断行对象当前的位置 3. 获取断行对象当前的位置。
调用current方法来获取断行对象在当前处理文本中的位置。 调用current方法来获取断行对象在当前处理文本中的位置。
...@@ -340,7 +364,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -340,7 +364,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var pos = breakIterator.current(); var pos = breakIterator.current();
``` ```
4. 设置断行对象的位置 4. 设置断行对象的位置。
系统提供了很多接口可以用于调整断行对象在处理文本中的位置,包括first, last, next, previous, following。 系统提供了很多接口可以用于调整断行对象在处理文本中的位置,包括first, last, next, previous, following。
...@@ -356,7 +381,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使 ...@@ -356,7 +381,8 @@ I18n开发指导提供了未在ECMA 402中定义的国际化能力接口的使
var followingPos = breakIterator.following(10); var followingPos = breakIterator.following(10);
``` ```
5. 判断某个位置是否为分割点 5. 判断某个位置是否为分割点。
调用isBoundary方法来判断一个方法是否为分割点;如果该位置是分割点,则返回true,并且将断行对象移动到该位置;如果该位置不是分割点,则返回false,并且将断行对象移动到该位置后的一个分割点。 调用isBoundary方法来判断一个方法是否为分割点;如果该位置是分割点,则返回true,并且将断行对象移动到该位置;如果该位置不是分割点,则返回false,并且将断行对象移动到该位置后的一个分割点。
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方法。 Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方法。
## 设置区域信息 ## 设置区域信息
调用[Locale](../reference/apis/js-apis-intl.md)的相关接口实现最大化区域信息或最小化区域信息。 调用[Locale](../reference/apis/js-apis-intl.md)的相关接口实现最大化区域信息或最小化区域信息。
...@@ -10,44 +9,48 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -10,44 +9,48 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | -------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 实例化Locale对象。 | | ohos.intl | constructor()<sup>8+</sup> | 实例化Locale对象。 |
| ohos.intl | constructor(locale:&nbsp;string,&nbsp;options?:&nbsp;LocaleOptions) | 基于locale参数及其选项实例化Locale对象。 | | ohos.intl | constructor(locale:string,options?:LocaleOptions) | 基于locale参数及其选项实例化Locale对象。 |
| ohos.intl | toString():&nbsp;string | 将Locale信息转换为字符串。 | | ohos.intl | toString():string | 将Locale信息转换为字符串。 |
| ohos.intl | maximize():&nbsp;Locale | 最大化区域信息。 | | ohos.intl | maximize():Locale | 最大化区域信息。 |
| ohos.intl | minimize():&nbsp;Locale | 最小化区域信息。 | | ohos.intl | minimize():Locale | 最小化区域信息。 |
### 开发步骤 ### 开发步骤
1. 实例化Locale对象 1. 实例化Locale对象。
使用Locale的构造函数创建Locale对象,该方法接收一个表示Locale的字符串及可选的[属性](../reference/apis/js-apis-intl.md)列表(intl为导入的模块名)。
使用Locale的构造函数创建Locale对象,该方法接收一个表示Locale的字符串及可选的[属性](../reference/apis/js-apis-intl.md)列表(intl为导入的模块名)。
``` ```
var locale = "zh-CN"; var locale = "zh-CN";
var options = {caseFirst: false, calendar: "chinese", collation: pinyin}; var options = {caseFirst: false, calendar: "chinese", collation: pinyin};
var localeObj = new intl.Locale(locale, options); var localeObj = new intl.Locale(locale, options);
``` ```
2. 获取Locale的字符串表示 2. 获取Locale的字符串表示。
调用toString方法来获取Locale对象的字符串表示,其中包括了语言、区域及其他选项信息。
调用toString方法来获取Locale对象的字符串表示,其中包括了语言、区域及其他选项信息。
``` ```
var localeStr = localeObj.toString(); var localeStr = localeObj.toString();
``` ```
3. 最大化区域信息 3. 最大化区域信息。
调用maximize方法来最大化区域信息,即当缺少脚本与地区信息时,对其进行补全。
调用maximize方法来最大化区域信息,即当缺少脚本与地区信息时,对其进行补全。
``` ```
var maximizedLocale = localeObj.maximize(); var maximizedLocale = localeObj.maximize();
``` ```
4. 最小化区域信息 4. 最小化区域信息。
调用minimize方法来最小化区域信息,即当存在脚本与地区信息时,对其进行删除。
调用minimize方法来最小化区域信息,即当存在脚本与地区信息时,对其进行删除。
``` ```
var minimizedLocale = localeObj.minimize(); var minimizedLocale = localeObj.minimize();
``` ```
...@@ -60,52 +63,56 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -60,52 +63,56 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ---------------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 创建日期时间格式化对象。 | | ohos.intl | constructor()<sup>8+</sup> | 创建日期时间格式化对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;DateTimeOptions) | 创建日期时间格式化对象,并设置提供的Locale和格式化相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:DateTimeOptions) | 创建日期时间格式化对象,并设置提供的Locale和格式化相关属性。 |
| ohos.intl | format(date:&nbsp;Date):&nbsp;string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算日期时间的格式化表示。 | | ohos.intl | format(date:Date):string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算日期时间的格式化表示。 |
| ohos.intl | formatRange(startDate:&nbsp;Date,&nbsp;endDate:&nbsp;Date):&nbsp;string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算时间段的格式化表示。 | | ohos.intl | formatRange(startDate:Date,endDate:Date):string | 依据DateTimeFormat对象的Locale及其他格式化属性,计算时间段的格式化表示。 |
| ohos.intl | resolvedOptions():&nbsp;DateTimeOptions | 获取DateTimeFormat对象的相关属性。 | | ohos.intl | resolvedOptions():DateTimeOptions | 获取DateTimeFormat对象的相关属性。 |
### 开发步骤 ### 开发步骤
1. 实例化日期时间格式化对象 1. 实例化日期时间格式化对象。
一种方法是使用DateTimeFormat提供的默认构造函数,通过访问系统语言和地区设置,获取系统默认Locale,并将其作为DateTimeFormat对象内部的Locale(intl为导入的模块名)。
一种方法是使用DateTimeFormat提供的默认构造函数,通过访问系统语言和地区设置,获取系统默认Locale,并将其作为DateTimeFormat对象内部的Locale(intl为导入的模块名)。
``` ```
var dateTimeFormat = new intl.DateTimeFormat(); var dateTimeFormat = new intl.DateTimeFormat();
``` ```
另一种方法是使用开发者提供的Locale和格式化参数来创建日期时间格式化对象。其中,格式化参数是可选的,完整的格式化参数列表见[DateTimeOptions](../reference/apis/js-apis-intl.md)。 另一种方法是使用开发者提供的Locale和格式化参数来创建日期时间格式化对象。其中,格式化参数是可选的,完整的格式化参数列表见[DateTimeOptions](../reference/apis/js-apis-intl.md)。
``` ```
var options = {dateStyle: "full", timeStyle: "full"}; var options = {dateStyle: "full", timeStyle: "full"};
var dateTimeFormat = new intl.DateTimeFormat("zh-CN", options); var dateTimeFormat = new intl.DateTimeFormat("zh-CN", options);
``` ```
2. 格式化日期时间 2. 格式化日期时间。
使用DateTimeFormat的format方法对一个Date对象进行格式化,该方法会返回一个字符串作为格式化的结果。
使用DateTimeFormat的format方法对一个Date对象进行格式化,该方法会返回一个字符串作为格式化的结果。
``` ```
Date date = new Date(); Date date = new Date();
var formatResult = dateTimeFormat.format(date); var formatResult = dateTimeFormat.format(date);
``` ```
3. 格式化时间段 3. 格式化时间段。
使用DateTimeFormat的formatRange方法对一个时间段进行格式化。该方法需要传入两个Date对象,分别表示时间段的起止时间,返回一个字符串作为格式化的结果。
使用DateTimeFormat的formatRange方法对一个时间段进行格式化。该方法需要传入两个Date对象,分别表示时间段的起止时间,返回一个字符串作为格式化的结果。
``` ```
Date startDate = new Date(); Date startDate = new Date();
Date endDate = new Date(); Date endDate = new Date();
var formatResult = dateTimeFormat.formatRange(startDate, endDate); var formatResult = dateTimeFormat.formatRange(startDate, endDate);
``` ```
4. 访问日期时间格式化对象的相关属性 4. 访问日期时间格式化对象的相关属性。
DateTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了DateTimeFormat对象的所有相关属性及其值。
DateTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了DateTimeFormat对象的所有相关属性及其值。
``` ```
var options = dateTimeFormat.resolvedOptions(); var options = dateTimeFormat.resolvedOptions();
``` ```
...@@ -118,42 +125,45 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -118,42 +125,45 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ---------------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<SUP>8+</SUP> | 创建数字格式化对象。 | | ohos.intl | constructor()<SUP>8+</SUP> | 创建数字格式化对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;NumberOptions) | 创建数字格式化对象,并设置提供的locale和格式化相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:NumberOptions) | 创建数字格式化对象,并设置提供的locale和格式化相关属性。 |
| ohos.intl | format(number:&nbsp;number):&nbsp;string | 依据NumberFormat对象的Locale及其他格式化属性,计算数字的格式化表示。 | | ohos.intl | format(number:number):string | 依据NumberFormat对象的Locale及其他格式化属性,计算数字的格式化表示。 |
| ohos.intl | resolvedOptions():&nbsp;NumberOptions | 获取NumberFormat对象的相关属性。 | | ohos.intl | resolvedOptions():NumberOptions | 获取NumberFormat对象的相关属性。 |
### 开发步骤 ### 开发步骤
1. 实例化数字格式化对象 1. 实例化数字格式化对象。
一种方法是使用NumberFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
一种方法是使用NumberFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
``` ```
var numberFormat = new intl.NumberFormat(); var numberFormat = new intl.NumberFormat();
``` ```
另一种方法是使用开发者提供的Locale和格式化参数来创建数字格式化对象。其中,格式化参数是可选的,完整的格式化参数列表参见[NumberOptions](../reference/apis/js-apis-intl.md)。 另一种方法是使用开发者提供的Locale和格式化参数来创建数字格式化对象。其中,格式化参数是可选的,完整的格式化参数列表参见[NumberOptions](../reference/apis/js-apis-intl.md)。
``` ```
var options = {compactDisplay: "short", notation: "compact"}; var options = {compactDisplay: "short", notation: "compact"};
var numberFormat = new intl.NumberFormat("zh-CN", options); var numberFormat = new intl.NumberFormat("zh-CN", options);
``` ```
2. 数字格式化 2. 数字格式化。
使用NumberFormat的format方法对传入的数字进行格式化。该方法返回一个字符串作为格式化的结果。
使用NumberFormat的format方法对传入的数字进行格式化。该方法返回一个字符串作为格式化的结果。
``` ```
var number = 1234.5678 var number = 1234.5678
var formatResult = numberFormat.format(number); var formatResult = numberFormat.format(number);
``` ```
3. 访问数字格式化对象的相关属性 3. 访问数字格式化对象的相关属性。
NumberFormat的resolvedOptions方法会返回一个对象,该对象包含了NumberFormat对象的所有相关属性及其值。
NumberFormat的resolvedOptions方法会返回一个对象,该对象包含了NumberFormat对象的所有相关属性及其值。
``` ```
var options = numberFormat.resolvedOptions(); var options = numberFormat.resolvedOptions();
``` ```
...@@ -166,42 +176,45 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -166,42 +176,45 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 创建排序对象。 | | ohos.intl | constructor()<sup>8+</sup> | 创建排序对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;CollatorOptions)<sup>8+</sup> | 创建排序对象,并设置提供的locale和其他相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:CollatorOptions)<sup>8+</sup> | 创建排序对象,并设置提供的locale和其他相关属性。 |
| ohos.intl | compare(first:&nbsp;string,&nbsp;second:&nbsp;string):&nbsp;number<sup>8+</sup> | 依据排序对象的Locale及其属性,计算两个字符串的比较结果。 | | ohos.intl | compare(first:string,second:string):number<sup>8+</sup> | 依据排序对象的Locale及其属性,计算两个字符串的比较结果。 |
| ohos.intl | resolvedOptions():&nbsp;CollatorOptions<sup>8+</sup> | 获取排序对象的相关属性。 | | ohos.intl | resolvedOptions():CollatorOptions<sup>8+</sup> | 获取排序对象的相关属性。 |
### 开发步骤 ### 开发步骤
1. 实例化排序对象 1. 实例化排序对象。
一种方法是使用Collator提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
一种方法是使用Collator提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
``` ```
var collator = new intl.Collator(); var collator = new intl.Collator();
``` ```
另一种方法是使用开发者提供的Locale和其他相关参数来创建Collator对象,完整的参数列表参见[CollatorOptions](../reference/apis/js-apis-intl.md)。 另一种方法是使用开发者提供的Locale和其他相关参数来创建Collator对象,完整的参数列表参见[CollatorOptions](../reference/apis/js-apis-intl.md)。
``` ```
var collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"}; var collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"};
``` ```
2. 比较字符串 2. 比较字符串。
使用Collator的compare方法对传入的两个字符串进行比较。该方法返回一个数值作为比较的结果,返回-1表示第一个字符串小于第二个字符串,返回1表示第一个字符大于第二个字符串,返回0表示两个字符串相同。
使用Collator的compare方法对传入的两个字符串进行比较。该方法返回一个数值作为比较的结果,返回-1表示第一个字符串小于第二个字符串,返回1表示第一个字符大于第二个字符串,返回0表示两个字符串相同。
``` ```
var str1 = "first string"; var str1 = "first string";
var str2 = "second string"; var str2 = "second string";
var compareResult = collator.compare(str1, str2); var compareResult = collator.compare(str1, str2);
``` ```
3. 访问排序对象的相关属性 3. 访问排序对象的相关属性。
Collator的resolvedOptions方法会返回一个对象,该对象包含了Collator对象的所有相关属性及其值。
Collator的resolvedOptions方法会返回一个对象,该对象包含了Collator对象的所有相关属性及其值。
``` ```
var options = collator.resolvedOptions(); var options = collator.resolvedOptions();
``` ```
...@@ -214,32 +227,34 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -214,32 +227,34 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ---------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 创建单复数对象。 | | ohos.intl | constructor()<sup>8+</sup> | 创建单复数对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;PluralRulesOptions)<sup>8+</sup> | 创建单复数对象,并设置提供的locale和其他相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:PluralRulesOptions)<sup>8+</sup> | 创建单复数对象,并设置提供的locale和其他相关属性。 |
| ohos.intl | select(n:&nbsp;number):&nbsp;string<sup>8+</sup> | 依据单复数对象的Locale及其他格式化属性,计算数字的单复数类别。 | | ohos.intl | select(n:number):string<sup>8+</sup> | 依据单复数对象的Locale及其他格式化属性,计算数字的单复数类别。 |
### 开发步骤 ### 开发步骤
1. 实例化单复数对象 1. 实例化单复数对象。
一种方法是使用PluralRules提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
一种方法是使用PluralRules提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
``` ```
var pluralRules = new intl.PluralRules(); var pluralRules = new intl.PluralRules();
``` ```
另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md)。 另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md)。
``` ```
var plurals = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"}; var plurals = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"};
``` ```
2. 计算数字单复数类别 2. 计算数字单复数类别。
使用PluralRules的select方法计算传入数字的单复数类别。该方法返回一个字符串作为传入数字的类别,包括:"zero", "one", "two", "few", "many", "other"六个类别。
使用PluralRules的select方法计算传入数字的单复数类别。该方法返回一个字符串作为传入数字的类别,包括:"zero", "one", "two", "few", "many", "other"六个类别。
``` ```
var number = 1234.5678 var number = 1234.5678
var categoryResult = plurals.select(number); var categoryResult = plurals.select(number);
...@@ -253,52 +268,56 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方 ...@@ -253,52 +268,56 @@ Intl开发指导提供了ECMA 402中定义的国际化能力接口的使用方
### 接口说明 ### 接口说明
| 模块 | 接口名称 | 描述 | | 模块 | 接口名称 | 描述 |
| --------- | ---------------------------------------- | ---------------------------------------- | | -------- | -------- | -------- |
| ohos.intl | constructor()<sup>8+</sup> | 创建相对时间格式化对象。 | | ohos.intl | constructor()<sup>8+</sup> | 创建相对时间格式化对象。 |
| ohos.intl | constructor(locale:&nbsp;string&nbsp;\|&nbsp;Array&lt;string&gt;,&nbsp;options?:&nbsp;RelativeTimeFormatInputOptions)<sup>8+</sup> | 创建相对时间格式化对象,并设置提供的locale和格式化相关属性。 | | ohos.intl | constructor(locale:string\|Array&lt;string&gt;,options?:RelativeTimeFormatInputOptions)<sup>8+</sup> | 创建相对时间格式化对象,并设置提供的locale和格式化相关属性。 |
| ohos.intl | format(value:&nbsp;number,&nbsp;unit:&nbsp;string):&nbsp;string<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,计算相对时间的格式化表示。 | | ohos.intl | format(value:number,unit:string):string<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,计算相对时间的格式化表示。 |
| ohos.intl | formatToParts(value:&nbsp;number,&nbsp;unit:&nbsp;string):&nbsp;Array&lt;object&gt;<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,返回相对时间格式化表示的各个部分。 | | ohos.intl | formatToParts(value:number,unit:string):Array&lt;object&gt;<sup>8+</sup> | 依据相对时间格式化对象的Locale及其他格式化属性,返回相对时间格式化表示的各个部分。 |
| ohos.intl | resolvedOptions():&nbsp;RelativeTimeFormatResolvedOptions<sup>8+</sup> | 获取相对时间格式化对象的相关属性。 | | ohos.intl | resolvedOptions():RelativeTimeFormatResolvedOptions<sup>8+</sup> | 获取相对时间格式化对象的相关属性。 |
### 开发步骤 ### 开发步骤
1. 实例化相对时间格式化对象 1. 实例化相对时间格式化对象。
一种方法是使用RelativeTimeFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
一种方法是使用RelativeTimeFormat提供的默认构造函数,通过访问系统的语言和地区以获取系统默认Locale并进行设置(intl为导入的模块名)。
``` ```
var relativeTimeFormat = new intl.RelativeTimeFormat(); var relativeTimeFormat = new intl.RelativeTimeFormat();
``` ```
另一种方法是使用开发者提供的Locale和格式化参数来创建相对时间格式化对象。其中,格式化参数是可选的,完整的参数列表参见[ RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md)。 另一种方法是使用开发者提供的Locale和格式化参数来创建相对时间格式化对象。其中,格式化参数是可选的,完整的参数列表参见[ RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md)。
``` ```
var relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"}; var relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"};
``` ```
2. 相对时间格式化 2. 相对时间格式化。
使用RelativeTimeFormat的format方法对相对时间进行格式化。方法接收一个表示相对时间长度的数值和表示单位的字符串,其中单位包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。方法返回一个字符串作为格式化的结果。
使用RelativeTimeFormat的format方法对相对时间进行格式化。方法接收一个表示相对时间长度的数值和表示单位的字符串,其中单位包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。方法返回一个字符串作为格式化的结果。
``` ```
var number = 2; var number = 2;
var unit = "year" var unit = "year"
var formatResult = relativeTimeFormat.format(number, unit); var formatResult = relativeTimeFormat.format(number, unit);
``` ```
3. 获取相对时间格式化结果的各个部分 3. 获取相对时间格式化结果的各个部分。
获取相对时间格式化结果的各个部分,从而自定义格式化结果。
获取相对时间格式化结果的各个部分,从而自定义格式化结果。
``` ```
var number = 2; var number = 2;
var unit = "year" var unit = "year"
var formatResult = relativeTimeFormat.formatToParts(number, unit); var formatResult = relativeTimeFormat.formatToParts(number, unit);
``` ```
4. 访问相对时间格式化对象的相关属性 4. 访问相对时间格式化对象的相关属性。
RelativeTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了RelativeTimeFormat对象的所有相关属性及其值,完整的属性列表参见[ RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md)
RelativeTimeFormat的resolvedOptions方法会返回一个对象,该对象包含了RelativeTimeFormat对象的所有相关属性及其值,完整的属性列表参见[ RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md)。
``` ```
var options = numberFormat.resolvedOptions(); var options = numberFormat.resolvedOptions();
``` ```
......
...@@ -20,7 +20,7 @@ resources ...@@ -20,7 +20,7 @@ resources
| | |---string.json | | |---string.json
| |---media | |---media
| | |---icon.png | | |---icon.png
|---rawfile // 默认存在的目录 |---rawfile
``` ```
**表1** resources目录分类 **表1** resources目录分类
......
...@@ -18,18 +18,18 @@ ...@@ -18,18 +18,18 @@
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core **系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 | | 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| resourceManager | ResourceManager | 是 | 否 | ResourceManager对象。 | | resourceManager | ResourceManager | 是 | 否 | ResourceManager对象。 |
| applicationInfo | ApplicationInfo | 是 | 否 | 当前应用信息。 | | applicationInfo | ApplicationInfo | 是 | 否 | 当前应用信息。 |
| cacheDir | string | 是 | 否 | 应用在内部存储上的缓存路径。 | | cacheDir | string | 是 | 否 | 应用在内部存储上的缓存路径。 |
| tempDir | string | 是 | 否 | 应用的临时文件路径。 | | tempDir | string | 是 | 否 | 应用的临时文件路径。 |
| filesDir | string | 是 | 否 | 应用在内部存储上的文件路径。 | | filesDir | string | 是 | 否 | 应用在内部存储上的文件路径。 |
| databaseDir | string | 是 | 否 | 获取本地数据存储路径。 | | databaseDir | string | 是 | 否 | 获取本地数据存储路径。 |
| storageDir | string | 是 | 否 | 获取轻量级数据存储路径。 | | storageDir | string | 是 | 否 | 获取轻量级数据存储路径。 |
| bundleCodeDir | string | 是 | 否 | 应用安装路径。 | | bundleCodeDir | string | 是 | 否 | 应用安装路径。 |
| distributedFilesDir | string | 是 | 否 | 应用的分布式文件路径。 | | distributedFilesDir | string | 是 | 否 | 应用的分布式文件路径。 |
| eventHub | [EventHub](js-apis-eventhub.md) | 是 | 否 | 事件中心信息。| | eventHub | [EventHub](js-apis-eventhub.md) | 是 | 否 | 事件中心信息。|
## Context.createBundleContext ## Context.createBundleContext
...@@ -42,15 +42,15 @@ createBundleContext(bundleName: string): Context; ...@@ -42,15 +42,15 @@ createBundleContext(bundleName: string): Context;
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 应用bundle名。 | | bundleName | string | 是 | 应用bundle名。 |
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Context | 对应创建应用的上下文context。 | | Context | 对应创建应用的上下文context。 |
**示例:** **示例:**
...@@ -70,13 +70,51 @@ getApplicationContext(): Context; ...@@ -70,13 +70,51 @@ getApplicationContext(): Context;
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------- | -------- | | -------- | -------- |
| Context | 当前Context&nbsp;信息。 | | Context | 当前Context&nbsp;信息。 |
**示例:** **示例:**
```js ```js
// 必选项。 // 必选项。
let context = this.context.getApplicationContext(); let context = this.context.getApplicationContext();
``` ```
> **说明:**
> 当SDK :API 9版本为Canary版本时;
## Context.switchArea
switchArea(mode: AreaMode): void
开启文件范围
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------ | --------------------- | ---- | -------------- |
| mode | [AreaMode](#AreaMode) | 是 | 应用bundle名。 |
**示例**
```js
var areaMode = 0
this.context.switchArea(areaMode);
```
## AreaMode
文件范围模式
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 参数类型 | 值 |
| ---- | -------- | ---- |
| EL1 | number | 0 |
| EL2 | number | 1 |
\ No newline at end of file
# Context
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明**
>
> 本模块首批接口从API version 9开始支持。API 9当前为Canary版本,仅供使用,不保证接口可稳定调用。
提供开发者运行代码的上下文环境,包括应用信息、ResourceManager等信息。
## 使用说明
通过AbilityContext等继承实现。
## 属性
**系统能力**:以下各项对应的系统能力均为SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| resourceManager | ResourceManager | 是 | 否 | ResourceManager对象。 |
| applicationInfo | ApplicationInfo | 是 | 否 | 当前应用信息。 |
| cacheDir | string | 是 | 否 | 应用在内部存储上的缓存路径。 |
| tempDir | string | 是 | 否 | 应用的临时文件路径。 |
| filesDir | string | 是 | 否 | 应用在内部存储上的文件路径。 |
| databaseDir | string | 是 | 否 | 获取本地数据存储路径。 |
| storageDir | string | 是 | 否 | 获取轻量级数据存储路径。 |
| bundleCodeDir | string | 是 | 否 | 应用安装路径。 |
| distributedFilesDir | string | 是 | 否 | 应用的分布式文件路径。 |
| eventHub | [EventHub](js-apis-eventhub.md) | 是 | 否 | 事件中心信息。|
## Context.createBundleContext
createBundleContext(bundleName: string): Context;
创建指定应用上下文。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| bundleName | string | 是 | 应用bundle名。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Context | 对应创建应用的上下文context。 |
**示例:**
```js
let test = "com.example.test";
let context = this.context.createBundleContext(test);
```
## Context.getApplicationContext
getApplicationContext(): Context;
获取当前context。
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Context | 当前Context&nbsp;信息。 |
**示例:**
```js
// 必选项。
let context = this.context.getApplicationContext();
```
## Context.switchArea
switchArea(mode: AreaMode): void
开启文件范围
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| mode | [AreaMode](#AreaMode) | 是 | 应用bundle名。 |
**示例**
```js
var areaMode = 0
this.context.switchArea(areaMode);
```
## AreaMode
文件范围模式
**系统能力**:SystemCapability.Ability.AbilityRuntime.Core
| 名称 | 参数类型 | 值 |
| -------- | -------- | -------- |
| EL1 | number | 0 |
| EL2 | number | 1 |
\ No newline at end of file
# 配置策略 # 配置策略
配置策略提供按预先定义的定制配置层级获取对应定制配置目录和文件路径的能力。
> **说明:** > **说明:**
> >
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> >
> 本模块接口均为系统接口,三方应用不支持调用。 > 本模块接口均为系统接口,三方应用不支持调用。
配置策略提供按预先定义的定制配置层级获取对应定制配置目录和文件路径的能力。
## 导入模块 ## 导入模块
```js ```js
...@@ -16,10 +16,10 @@ import configPolicy from '@ohos.configPolicy'; ...@@ -16,10 +16,10 @@ import configPolicy from '@ohos.configPolicy';
## getOneCfgFile ## getOneCfgFile
getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;): void getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;)
使用callback形式返回指定文件名的最高优先级配置文件路径。 使用callback形式返回指定文件名的最高优先级配置文件路径。
例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、/sys-pod/etc/config.xml,最终返回/sys-pod/etc/config.xml。 例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、/sys_pod/etc/config.xml,最终返回/sys_pod/etc/config.xml。
**系统能力**:SystemCapability.Customization.ConfigPolicy **系统能力**:SystemCapability.Customization.ConfigPolicy
...@@ -31,7 +31,7 @@ getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;): void ...@@ -31,7 +31,7 @@ getOneCfgFile(relPath: string, callback: AsyncCallback&lt;string&gt;): void
**示例:** **示例:**
```js ```js
configPolicy.getOneCfgFile('config.xml', (error, value) => { configPolicy.getOneCfgFile('etc/config.xml', (error, value) => {
if (error == undefined) { if (error == undefined) {
console.log("value is " + value); console.log("value is " + value);
} else { } else {
...@@ -61,7 +61,7 @@ getOneCfgFile(relPath: string): Promise&lt;string&gt; ...@@ -61,7 +61,7 @@ getOneCfgFile(relPath: string): Promise&lt;string&gt;
**示例:** **示例:**
```js ```js
configPolicy.getOneCfgFile('config.xml').then(value => { configPolicy.getOneCfgFile('etc/config.xml').then(value => {
console.log("value is " + value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getOneCfgFile promise " + error); console.log("getOneCfgFile promise " + error);
...@@ -71,10 +71,10 @@ getOneCfgFile(relPath: string): Promise&lt;string&gt; ...@@ -71,10 +71,10 @@ getOneCfgFile(relPath: string): Promise&lt;string&gt;
## getCfgFiles ## getCfgFiles
getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
按优先级从低到高,使用callback形式返回指定文件名所有的文件列表。例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、 按优先级从低到高,使用callback形式返回指定文件名所有的文件列表。例如,config.xml在设备中存在以下路径(优先级从低到高):/system/etc/config.xml、
/sys-pod/etc/config.xml,最终返回/system/etc/config.xml, /sys-pod/etc/config.xml。 /sys_pod/etc/config.xml,最终返回/system/etc/config.xml, /sys_pod/etc/config.xml。
**系统能力**:SystemCapability.Customization.ConfigPolicy **系统能力**:SystemCapability.Customization.ConfigPolicy
...@@ -86,7 +86,7 @@ getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;) ...@@ -86,7 +86,7 @@ getCfgFiles(relPath: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
**示例:** **示例:**
```js ```js
configPolicy.getCfgFiles('config.xml', (error, value) => { configPolicy.getCfgFiles('etc/config.xml', (error, value) => {
if (error == undefined) { if (error == undefined) {
console.log("value is " + value); console.log("value is " + value);
} else { } else {
...@@ -116,7 +116,7 @@ getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt; ...@@ -116,7 +116,7 @@ getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt;
**示例:** **示例:**
```js ```js
configPolicy.getCfgFiles('config.xml').then(value => { configPolicy.getCfgFiles('etc/config.xml').then(value => {
console.log("value is " + value); console.log("value is " + value);
}).catch(error => { }).catch(error => {
console.log("getCfgFiles promise " + error); console.log("getCfgFiles promise " + error);
...@@ -126,7 +126,7 @@ getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt; ...@@ -126,7 +126,7 @@ getCfgFiles(relPath: string): Promise&lt;Array&lt;string&gt;&gt;
## getCfgDirList ## getCfgDirList
getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void getCfgDirList(callback: AsyncCallback&lt;Array&lt;string&gt;&gt;)
使用callback形式返回配置层级目录列表。 使用callback形式返回配置层级目录列表。
......
...@@ -46,10 +46,10 @@ isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void ...@@ -46,10 +46,10 @@ isIdleState(bundleName: string, callback: AsyncCallback&lt;boolean&gt;): void
``` ```
bundleState.isIdleState("com.ohos.camera", (err, res) => { bundleState.isIdleState("com.ohos.camera", (err, res) => {
if(err.code === 0) { if (err) {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code); console.log('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
} }
}); });
``` ```
...@@ -77,9 +77,9 @@ isIdleState(bundleName: string): Promise&lt;boolean&gt; ...@@ -77,9 +77,9 @@ isIdleState(bundleName: string): Promise&lt;boolean&gt;
**示例** **示例**
``` ```
bundleState.isIdleState("com.ohos.camera").then( res => { bundleState.isIdleState("com.ohos.camera").then(res => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
}); });
``` ```
...@@ -102,10 +102,10 @@ queryAppUsagePriorityGroup(callback: AsyncCallback&lt;number&gt;): void ...@@ -102,10 +102,10 @@ queryAppUsagePriorityGroup(callback: AsyncCallback&lt;number&gt;): void
``` ```
bundleState.queryAppUsagePriorityGroup((err, res) => { bundleState.queryAppUsagePriorityGroup((err, res) => {
if(err.code === 0) { if (err) {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback failed. because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup callback succeeded. result: ' + JSON.stringify(res));
} }
}); });
``` ```
...@@ -127,9 +127,9 @@ queryAppUsagePriorityGroup(): Promise&lt;number&gt; ...@@ -127,9 +127,9 @@ queryAppUsagePriorityGroup(): Promise&lt;number&gt;
**示例** **示例**
``` ```
bundleState.queryAppUsagePriorityGroup().then( res => { bundleState.queryAppUsagePriorityGroup().then(res => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res)); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code); console.log('BUNDLE_ACTIVE queryAppUsagePriorityGroup promise failed. because: ' + err.code);
}); });
``` ```
...@@ -158,16 +158,16 @@ queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback&lt;Bun ...@@ -158,16 +158,16 @@ queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback&lt;Bun
``` ```
bundleState.queryBundleStateInfos(0, 20000000000000, (err, res) => { bundleState.queryBundleStateInfos(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback success.');
let i = 1; let i = 1;
for(let key in res){ for (let key in res) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos callback result ' + JSON.stringify(res[key]));
i++; i++;
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfos callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -200,15 +200,15 @@ queryBundleStateInfos(begin: number, end: number): Promise&lt;BundleActiveInfoRe ...@@ -200,15 +200,15 @@ queryBundleStateInfos(begin: number, end: number): Promise&lt;BundleActiveInfoRe
**示例** **示例**
``` ```
bundleState.queryBundleStateInfos(0, 20000000000000).then( res => { bundleState.queryBundleStateInfos(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise success.');
let i = 1; let i = 1;
for(let key in res){ for (let key in res) {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise number : ' + i);
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key])); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise result ' + JSON.stringify(res[key]));
i++; i++;
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfos promise failed, because: ' + err.code);
}); });
``` ```
...@@ -238,14 +238,14 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num ...@@ -238,14 +238,14 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num
``` ```
bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => { bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -279,13 +279,13 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num ...@@ -279,13 +279,13 @@ queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: num
**示例** **示例**
``` ```
bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000).then( res => { bundleState.queryBundleStateInfoByInterval(0, 0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.'); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleStateInfoByInterval promise failed, because: ' + err.code);
}); });
``` ```
...@@ -314,14 +314,14 @@ queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback&lt;A ...@@ -314,14 +314,14 @@ queryBundleActiveStates(begin: number, end: number, callback: AsyncCallback&lt;A
``` ```
bundleState.queryBundleActiveStates(0, 20000000000000, (err, res) => { bundleState.queryBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleActiveStates callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryBundleActiveStates callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -354,13 +354,13 @@ queryBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;BundleA ...@@ -354,13 +354,13 @@ queryBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;BundleA
**示例** **示例**
``` ```
bundleState.queryBundleActiveStates(0, 20000000000000).then( res => { bundleState.queryBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryBundleActiveStates promise failed, because: ' + err.code);
}); });
``` ```
...@@ -385,14 +385,14 @@ queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallba ...@@ -385,14 +385,14 @@ queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallba
``` ```
bundleState.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => { bundleState.queryCurrentBundleActiveStates(0, 20000000000000, (err, res) => {
if(err.code == 0) { if (err) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback result ' + JSON.stringify(res[i]));
} }
} else {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates callback failed, because: ' + err.code);
} }
}); });
``` ```
...@@ -421,13 +421,13 @@ queryCurrentBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt; ...@@ -421,13 +421,13 @@ queryCurrentBundleActiveStates(begin: number, end: number): Promise&lt;Array&lt;
**示例** **示例**
``` ```
bundleState.queryCurrentBundleActiveStates(0, 20000000000000).then( res => { bundleState.queryCurrentBundleActiveStates(0, 20000000000000).then(res => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.'); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise success.');
for (let i = 0; i < res.length; i++) { for (let i = 0; i < res.length; i++) {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1)); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise number : ' + (i + 1));
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i])); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise result ' + JSON.stringify(res[i]));
} }
}).catch( err => { }).catch(err => {
console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code); console.log('BUNDLE_ACTIVE queryCurrentBundleActiveStates promise failed, because: ' + err.code);
}); });
``` ```
......
...@@ -12,28 +12,28 @@ import document from '@ohos.document'; ...@@ -12,28 +12,28 @@ import document from '@ohos.document';
## document.choose ## document.choose
choose(types:string[]): Promise&lt;string&gt; choose(types? : string[]): Promise&lt;string&gt;
通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。 通过文件管理器选择文件,异步返回文件URI,使用promise形式返回结果。
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------ | ---- | ---------------------------- | | ------ | ------ | ---- | ---------------------------- |
| types | string[] | 否 | 限定文件选择的类型 | | types | string[] | 否 | 限定文件选择的类型 |
- 返回值: **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | -------------- | | --------------------- | -------------- |
| Promise&lt;string&gt; | 异步返回文件URI(注:当前返回错误码) | | Promise&lt;string&gt; | 异步返回文件URI(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let tpyes = []; let types = [];
document.choose(types); document.choose(types);
``` ```
## document.choose ## document.choose
...@@ -44,13 +44,13 @@ choose(callback:AsyncCallback&lt;string&gt;): void ...@@ -44,13 +44,13 @@ choose(callback:AsyncCallback&lt;string&gt;): void
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| callback | AsyncCallback&lt;string&gt; | 是 | 异步获取对应文件URI(注:当前返回错误码) | | callback | AsyncCallback&lt;string&gt; | 是 | 异步获取对应文件URI(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let uri = ""; let uri = "";
...@@ -66,14 +66,14 @@ choose(types:string[], callback:AsyncCallback&lt;string&gt;): void ...@@ -66,14 +66,14 @@ choose(types:string[], callback:AsyncCallback&lt;string&gt;): void
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
| types | string[] | 否 | 限定选择文件的类型 | | types | string[] | 否 | 限定选择文件的类型 |
| callback | AsyncCallback&lt;string&gt; | 是 | 异步获取对应文件URI(注:当前返回错误码) | | callback | AsyncCallback&lt;string&gt; | 是 | 异步获取对应文件URI(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let types = []; let types = [];
...@@ -91,20 +91,20 @@ show(uri:string, type:string):Promise&lt;void&gt; ...@@ -91,20 +91,20 @@ show(uri:string, type:string):Promise&lt;void&gt;
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数 | 类型 | 必填 | 说明 | | 参数 | 类型 | 必填 | 说明 |
| ---- | ------ | ---- | ---------------------------- | | ---- | ------ | ---- | ---------------------------- |
| uri | string | 是 | 待打开的文件URI | | uri | string | 是 | 待打开的文件URI |
| type | string | 是 | 待打开文件的类型 | | type | string | 是 | 待打开文件的类型 |
- 返回值: **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------ | | --------------------- | ------------ |
| Promise&lt;void&gt; | Promise回调返回void表示成功打开文件(注:当前返回错误码) | | Promise&lt;void&gt; | Promise回调返回void表示成功打开文件(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let type = ""; let type = "";
...@@ -120,7 +120,7 @@ show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void ...@@ -120,7 +120,7 @@ show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数: **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------- | ---- | ---------------------------- | | -------- | --------------------------- | ---- | ---------------------------- |
...@@ -128,7 +128,7 @@ show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void ...@@ -128,7 +128,7 @@ show(uri:string, type:string, callback:AsyncCallback&lt;void&gt;): void
| type | string | 是 | 待打开文件的类型 | | type | string | 是 | 待打开文件的类型 |
| callback | AsyncCallback&lt;void&gt; | 是 | 异步打开uri对应文件(注:当前返回错误码) | | callback | AsyncCallback&lt;void&gt; | 是 | 异步打开uri对应文件(注:当前返回错误码) |
- 示例: **示例:**
```js ```js
let type = ""; let type = "";
......
# 目录环境能力 # 目录环境能力
该模块提供环境目录能力,获取内存存储根目录、公共文件根目录的JS接口。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> >
> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块接口为系统接口,三方应用不支持调用。 > - 本模块接口为系统接口,三方应用不支持调用。
该模块提供环境目录能力,获取内存存储根目录、公共文件根目录的JS接口。
## 导入模块 ## 导入模块
```js ```js
......
# 文件管理 # 文件管理
该模块提供文件存储管理能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读写等常用功能。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件存储管理能力,包括文件基本管理、文件目录管理、文件信息统计、文件流式读写等常用功能。
## 导入模块 ## 导入模块
```js ```js
...@@ -22,7 +22,7 @@ import fileio from '@ohos.fileio'; ...@@ -22,7 +22,7 @@ import fileio from '@ohos.fileio';
context.getFilesDir().then((data) => { context.getFilesDir().then((data) => {
path = data; path = data;
}) })
``` ```
## fileio.stat ## fileio.stat
...@@ -546,7 +546,7 @@ open(path: string, flags?: number, mode?: number): Promise&lt;number&gt; ...@@ -546,7 +546,7 @@ open(path: string, flags?: number, mode?: number): Promise&lt;number&gt;
```js ```js
fileio.open(path, 0o1, 0o0200).then(function(number){ fileio.open(path, 0o1, 0o0200).then(function(number){
console.info("open file succeed"); console.info("open file succeed");
}).catch(function(error){ }).catch(function(err){
console.info("open file failed with error:"+ err); console.info("open file failed with error:"+ err);
}); });
``` ```
...@@ -639,11 +639,11 @@ read(fd: number, buffer: ArrayBuffer, options?: { ...@@ -639,11 +639,11 @@ read(fd: number, buffer: ArrayBuffer, options?: {
```js ```js
let fd = fileio.openSync(path, 0o2); let fd = fileio.openSync(path, 0o2);
let buf = new ArrayBuffer(4096); let buf = new ArrayBuffer(4096);
fileio.read(fd, buf).then(function(readout){ fileio.read(fd, buf).then(function(readOut){
console.info("read file data succeed"); console.info("read file data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
}).catch(function(error){ }).catch(function(err){
console.info("read file data failed with error:"+ error); console.info("read file data failed with error:"+ err);
}); });
``` ```
...@@ -879,7 +879,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: { ...@@ -879,7 +879,7 @@ write(fd: number, buffer: ArrayBuffer | string, options?: {
**示例:** **示例:**
```js ```js
let fd = fileio.openSync(fpath, 0o100 | 0o2, 0o666); let fd = fileio.openSync(path, 0o100 | 0o2, 0o666);
fileio.write(fd, "hello, world").then(function(number){ fileio.write(fd, "hello, world").then(function(number){
console.info("write data to file succeed and size is:"+ number); console.info("write data to file succeed and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
...@@ -998,7 +998,7 @@ hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): vo ...@@ -998,7 +998,7 @@ hash(path: string, algorithm: string, callback: AsyncCallback&lt;string&gt;): vo
**示例:** **示例:**
```js ```js
fileio.hash(fpath, "sha256", function(err, hashStr) { fileio.hash(path, "sha256", function(err, hashStr) {
if (hashStr) { if (hashStr) {
console.info("calculate file hash succeed:"+ hashStr); console.info("calculate file hash succeed:"+ hashStr);
} }
...@@ -1074,7 +1074,7 @@ chmodSync(path: string, mode: number): void ...@@ -1074,7 +1074,7 @@ chmodSync(path: string, mode: number): void
**示例:** **示例:**
```js ```js
fileio.chmodSync(fpath, mode); fileio.chmodSync(path, mode);
``` ```
...@@ -1409,7 +1409,7 @@ lstat(path: string): Promise&lt;Stat&gt; ...@@ -1409,7 +1409,7 @@ lstat(path: string): Promise&lt;Stat&gt;
**示例:** **示例:**
```js ```js
fileio.lstat(path).then(function(stat){ fileio.lstat(path).then(function(stat){
console.info("get link status succeed:"+ number); console.info("get link status succeed:"+ JSON.stringify(stat));
}).catch(function(err){ }).catch(function(err){
console.info("get link status failed with error:"+ err); console.info("get link status failed with error:"+ err);
}); });
...@@ -1663,7 +1663,7 @@ fsyncSync(fd: number): void ...@@ -1663,7 +1663,7 @@ fsyncSync(fd: number): void
**示例:** **示例:**
```js ```js
fileio.fyncsSync(fd); fileio.fsyncSync(fd);
``` ```
...@@ -1857,7 +1857,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt ...@@ -1857,7 +1857,7 @@ chown(path: string, uid: number, gid: number, callback: AsyncCallback&lt;void&gt
**示例:** **示例:**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(path)
fileio.chown(path, stat.uid, stat.gid, function (err){ fileio.chown(path, stat.uid, stat.gid, function (err){
// do something // do something
}); });
...@@ -1881,7 +1881,7 @@ chownSync(path: string, uid: number, gid: number): void ...@@ -1881,7 +1881,7 @@ chownSync(path: string, uid: number, gid: number): void
**示例:** **示例:**
```js ```js
let stat = fileio.statSync(fpath) let stat = fileio.statSync(path)
fileio.chownSync(path, stat.uid, stat.gid); fileio.chownSync(path, stat.uid, stat.gid);
``` ```
...@@ -2078,7 +2078,7 @@ createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;): ...@@ -2078,7 +2078,7 @@ createStream(path: string, mode: string, callback: AsyncCallback&lt;Stream&gt;):
**示例:** **示例:**
```js ```js
fileio.createStream(path, mode, function(err, stream){ fileio.createStream(path, "r+", function(err, stream){
// do something // do something
}); });
``` ```
...@@ -2130,7 +2130,8 @@ fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt; ...@@ -2130,7 +2130,8 @@ fdopenStream(fd: number, mode: string): Promise&lt;Stream&gt;
**示例:** **示例:**
```js ```js
fileio.fdopenStream(fd, mode).then(function(stream){ let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+").then(function(stream){
console.info("openStream succeed"); console.info("openStream succeed");
}).catch(function(err){ }).catch(function(err){
console.info("openStream failed with error:"+ err); console.info("openStream failed with error:"+ err);
...@@ -2155,7 +2156,8 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): v ...@@ -2155,7 +2156,8 @@ fdopenStream(fd: number, mode: string, callback: AsyncCallback&lt;Stream&gt;): v
**示例:** **示例:**
```js ```js
fileio.fdopenStream(fd, mode, function (err, stream) { let fd = fileio.openSync(path);
fileio.fdopenStream(fd, "r+", function (err, stream) {
// do something // do something
}); });
``` ```
...@@ -2182,6 +2184,7 @@ fdopenStreamSync(fd: number, mode: string): Stream ...@@ -2182,6 +2184,7 @@ fdopenStreamSync(fd: number, mode: string): Stream
**示例:** **示例:**
```js ```js
let fd = fileio.openSync(path);
let ss = fileio.fdopenStreamSync(fd, "r+"); let ss = fileio.fdopenStreamSync(fd, "r+");
``` ```
...@@ -2235,7 +2238,7 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt; ...@@ -2235,7 +2238,7 @@ fchown(fd: number, uid: number, gid: number, callback: AsyncCallback&lt;void&gt;
**示例:** **示例:**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(path);
fileio.fchown(fd, stat.uid, stat.gid, function (err){ fileio.fchown(fd, stat.uid, stat.gid, function (err){
// do something // do something
}); });
...@@ -2259,7 +2262,7 @@ fchownSync(fd: number, uid: number, gid: number): void ...@@ -2259,7 +2262,7 @@ fchownSync(fd: number, uid: number, gid: number): void
**示例:** **示例:**
```js ```js
let stat = fileio.statSync(fpath); let stat = fileio.statSync(path);
fileio.fchownSync(fd, stat.uid, stat.gid); fileio.fchownSync(fd, stat.uid, stat.gid);
``` ```
...@@ -2364,9 +2367,11 @@ createWatcher(filename: string, events: number, callback: AsyncCallback&lt;numbe ...@@ -2364,9 +2367,11 @@ createWatcher(filename: string, events: number, callback: AsyncCallback&lt;numbe
**示例:** **示例:**
```js ```js
fileio.createWatcher(filename, events, function(watcher){ let filename = path +"/test.txt";
// do something fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
}); });
``` ```
...@@ -2498,7 +2503,7 @@ isFile(): boolean ...@@ -2498,7 +2503,7 @@ isFile(): boolean
**示例:** **示例:**
```js ```js
let isFile = fileio.statSync(fpath).isFile(); let isFile = fileio.statSync(path).isFile();
``` ```
...@@ -2555,7 +2560,13 @@ stop(): Promise&lt;void&gt; ...@@ -2555,7 +2560,13 @@ stop(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
fileio.stop(); let filename = path +"/test.txt";
let watcher = await fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
});
watcher.stop().then(function(){
console.info("close watcher succeed");
});
``` ```
...@@ -2574,13 +2585,17 @@ stop(callback: AsyncCallback&lt;void&gt;): void ...@@ -2574,13 +2585,17 @@ stop(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
fileio.stop(function(err){ let filename = path +"/test.txt";
// do something let watcher = await fileio.createWatcher(filename, 1, function(number){
console.info("Monitoring times: "+number);
}); });
watcher.stop(function(){
console.info("close watcher succeed");
})
``` ```
## Stream<sup>7+</sup> ## Stream
文件流,在调用Stream的方法前,需要先通过createStream()方法(同步或异步)来构建一个Stream实例。 文件流,在调用Stream的方法前,需要先通过createStream()方法(同步或异步)来构建一个Stream实例。
...@@ -2600,7 +2615,7 @@ close(): Promise&lt;void&gt; ...@@ -2600,7 +2615,7 @@ close(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.close().then(function(){ ss.close().then(function(){
console.info("close fileStream succeed"); console.info("close fileStream succeed");
}).catch(function(err){ }).catch(function(err){
...@@ -2624,7 +2639,7 @@ close(callback: AsyncCallback&lt;void&gt;): void ...@@ -2624,7 +2639,7 @@ close(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.close(function (err) { ss.close(function (err) {
// do something // do something
}); });
...@@ -2641,7 +2656,7 @@ closeSync(): void ...@@ -2641,7 +2656,7 @@ closeSync(): void
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.closeSync(); ss.closeSync();
``` ```
...@@ -2661,7 +2676,7 @@ flush(): Promise&lt;void&gt; ...@@ -2661,7 +2676,7 @@ flush(): Promise&lt;void&gt;
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flush().then(function (){ ss.flush().then(function (){
console.info("flush succeed"); console.info("flush succeed");
}).catch(function(err){ }).catch(function(err){
...@@ -2685,7 +2700,7 @@ flush(callback: AsyncCallback&lt;void&gt;): void ...@@ -2685,7 +2700,7 @@ flush(callback: AsyncCallback&lt;void&gt;): void
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flush(function (err) { ss.flush(function (err) {
// do something // do something
}); });
...@@ -2702,7 +2717,7 @@ flushSync(): void ...@@ -2702,7 +2717,7 @@ flushSync(): void
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(path); let ss= fileio.createStreamSync(path, "r+");
ss.flushSync(); ss.flushSync();
``` ```
...@@ -2733,7 +2748,7 @@ write(buffer: ArrayBuffer | string, options?: { ...@@ -2733,7 +2748,7 @@ write(buffer: ArrayBuffer | string, options?: {
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){ ss.write("hello, world",{offset: 1,length: 5,position: 5,encoding :'utf-8'}).then(function (number){
console.info("write succeed and size is:"+ number); console.info("write succeed and size is:"+ number);
}).catch(function(err){ }).catch(function(err){
...@@ -2764,7 +2779,7 @@ write(buffer: ArrayBuffer | string, options: { ...@@ -2764,7 +2779,7 @@ write(buffer: ArrayBuffer | string, options: {
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(fpath, "r+"); let ss= fileio.createStreamSync(path, "r+");
ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) { ss.write("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}, function (err, bytesWritten) {
if (bytesWritten) { if (bytesWritten) {
// do something // do something
...@@ -2800,7 +2815,7 @@ writeSync(buffer: ArrayBuffer | string, options?: { ...@@ -2800,7 +2815,7 @@ writeSync(buffer: ArrayBuffer | string, options?: {
**示例:** **示例:**
```js ```js
let ss= fileio.createStreamSync(fpath,"r+"); let ss= fileio.createStreamSync(path,"r+");
let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'}); let num = ss.writeSync("hello, world", {offset: 1, length: 5, position: 5, encoding :'utf-8'});
``` ```
...@@ -2830,7 +2845,7 @@ read(buffer: ArrayBuffer, options?: { ...@@ -2830,7 +2845,7 @@ read(buffer: ArrayBuffer, options?: {
**示例:** **示例:**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){ ss.read(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}).then(function (readout){
console.info("read data succeed"); console.info("read data succeed");
console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer))); console.log(String.fromCharCode.apply(null, new Uint8Array(readOut.buffer)));
...@@ -2861,7 +2876,7 @@ read(buffer: ArrayBuffer, options: { ...@@ -2861,7 +2876,7 @@ read(buffer: ArrayBuffer, options: {
**示例:** **示例:**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) { ss.read(new ArrayBuffer(4096),{offset: 1, length: 5, position: 5},function (err, readOut) {
if (readOut) { if (readOut) {
console.info("read data succeed"); console.info("read data succeed");
...@@ -2898,7 +2913,7 @@ readSync(buffer: ArrayBuffer, options?: { ...@@ -2898,7 +2913,7 @@ readSync(buffer: ArrayBuffer, options?: {
**示例:** **示例:**
```js ```js
let ss = fileio.createStreamSync(fpath, "r+"); let ss = fileio.createStreamSync(path, "r+");
let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5}); let num = ss.readSync(new ArrayBuffer(4096), {offset: 1, length: 5, position: 5});
``` ```
......
# 公共文件访问与管理 # 公共文件访问与管理
该模块提供公共文件访问和管理的服务接口,向下对接底层文件管理服务,如媒体库、外卡管理;向上对应用程序提供公共文件查询、创建的能力。
>![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** >![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> >
>- 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 >- 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>- 本模块接口为系统接口,三方应用不支持调用,当前只支持filepicker调用。 >- 本模块接口为系统接口,三方应用不支持调用,当前只支持filepicker调用。
该模块提供公共文件访问和管理的服务接口,向下对接底层文件管理服务,如媒体库、外卡管理;向上对应用程序提供公共文件查询、创建的能力。
## 导入模块 ## 导入模块
```js ```js
...@@ -20,18 +21,18 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt; ...@@ -20,18 +21,18 @@ getRoot(options? : {dev? : DevInfo}) : Promise&lt;FileInfo[]&gt;
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | -- | | --- | --- | --- | -- |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --- | -- | | --- | -- |
| Promise&lt;[FileInfo](#fileinfo)[]&gt; | 第一层目录相册信息 | | Promise&lt;[FileInfo](#fileinfo)[]&gt; | 第一层目录相册信息 |
- 示例 **示例:**
```js ```js
filemanager.getRoot().then((fileInfo) => { filemanager.getRoot().then((fileInfo) => {
...@@ -53,22 +54,22 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;) ...@@ -53,22 +54,22 @@ getRoot(options? : {dev? : DevInfo}, callback : AsyncCallback&lt;FileInfo[]&gt;)
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' |
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 |
- 示例 **示例:**
```js ```js
let option = { let options = {
"dev":{ "dev":{
name:"", "name":"local"
} }
}; };
filemanager.getRoot(option,(err, fileInfo)=>{ filemanager.getRoot(options, (err, fileInfo)=>{
if(Array.isArray(fileInfo)) { if(Array.isArray(fileInfo)) {
for (var i = 0; i < fileInfo.length; i++) { for (var i = 0; i < fileInfo.length; i++) {
console.log("file:"+JSON.stringify(fileInfo)); console.log("file:"+JSON.stringify(fileInfo));
...@@ -86,27 +87,28 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -86,27 +87,28 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | -- | | --- | --- | --- | -- |
| path | string | 是 | 待查询目录uri | | path | string | 是 | 待查询目录uri |
| type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" | | type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local'。<br/>-&nbsp;offset,number类型,待查询文件偏移个数。<br/>-&nbsp;count,number类型,待查询文件个数。 | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local'。<br/>-&nbsp;offset,number类型,待查询文件偏移个数。<br/>-&nbsp;count,number类型,待查询文件个数。 |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --- | -- | | --- | -- |
| Promise&lt;FileInfo[]&gt; | 文件信息 | | Promise&lt;FileInfo[]&gt; | 文件信息 |
- 异常 **异常:**
| 错误名称 | 错误类型 | 错误码 |说明 | | 错误名称 | 错误类型 | 错误码 |说明 |
| --- | -- | --- | -- | | --- | -- | --- | -- |
| 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 | | 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 |
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 |
- 示例 **示例:**
```js ```js
// 获取目录下所有文件 // 获取目录下所有文件
...@@ -120,10 +122,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -120,10 +122,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
} }
} }
}).catch((err) => { }).catch((err) => {
console.log("failed to get file"+err);
console.log(err)
}); });
``` ```
...@@ -135,23 +134,24 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -135,23 +134,24 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | 是 | 待查询目录uri | | path | string | 是 | 待查询目录uri |
| type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" | | type | string | 是 | 待查询文件类型, 支持以下类型 "file", "image", "audio", "video" |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local'。<br/>-&nbsp;offset,number类型,待查询文件偏移个数。<br/>-&nbsp;count,number类型,待查询文件个数。 | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local'。<br/>-&nbsp;offset,number类型,待查询文件偏移个数。<br/>-&nbsp;count,number类型,待查询文件个数。 |
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 |
- 异常
| 错误名称 | 错误类型 | 错误码 | 说明 | **异常:**
| ------------------------- | ------------------------- | ------ | ------------------------- |
| 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 | | 错误名称 | 错误类型 | 错误码 | 说明 |
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | | ------------------------- | ------------------------- | ------ | ------------------------- |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | | 对应的目录、相册不存在 | No such file or directory | 2 | uri对应的目录、相册不存在 |
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 |
- 示例 **示例:**
```js ```js
// 通过listFile、getRoot获取的文件path // 通过listFile、getRoot获取的文件path
...@@ -177,7 +177,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num ...@@ -177,7 +177,7 @@ listFile(path : string, type : string, options? : {dev? : DevInfo, offset? : num
} }
} }
}).catch((err) => { }).catch((err) => {
console.log(err) console.log("failed to get file"+err);
}); });
``` ```
...@@ -189,20 +189,21 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P ...@@ -189,20 +189,21 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --- | --- | --- | -- | | --- | --- | --- | -- |
| filename | string | 是 | 待创建的文件名 | | filename | string | 是 | 待创建的文件名 |
| path | string | 是 | 待保存目的相册uri | | path | string | 是 | 待保存目的相册uri |
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --- | -- | | --- | -- |
| string | 文件uri | | Promise&lt;string&gt; | 文件uri |
**异常:**
- 异常
| 错误名称 | 错误类型 | 错误码 |说明 | | 错误名称 | 错误类型 | 错误码 |说明 |
| --- | -- | --- | -- | | --- | -- | --- | -- |
| 创建文件不允许 | Operation not permitted | 1 | 已有重名文件 | | 创建文件不允许 | Operation not permitted | 1 | 已有重名文件 |
...@@ -210,7 +211,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P ...@@ -210,7 +211,7 @@ createFile(path : string, filename : string, options? : {dev? : DevInfo}) : P
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 |
- 示例 **示例:**
```js ```js
// 创建文件,返回文件uri // 创建文件,返回文件uri
...@@ -232,7 +233,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -232,7 +233,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
**系统能力**:SystemCapability.FileManagement.UserFileService **系统能力**:SystemCapability.FileManagement.UserFileService
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | ----------------------------- | | -------- | ------------------------- | ---- | ----------------------------- |
...@@ -241,7 +242,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -241,7 +242,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
| options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' | | options | Object | 否 | 支持如下选项:<br/>-&nbsp;dev,[DevInfo](#devinfo)类型,不填默认dev = {name: "local"}, 当前仅支持设备'local' |
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 | | callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | 是 | 异步获取文件的信息之后的回调 |
- 异常 **异常:**
| 错误名称 | 错误类型 | 错误码 | 说明 | | 错误名称 | 错误类型 | 错误码 | 说明 |
| ------------------------- | ------------------------- | ------ | ------------------------- | | ------------------------- | ------------------------- | ------ | ------------------------- |
...@@ -250,7 +251,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -250,7 +251,7 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
| 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 | | 获取FMS服务失败 | No such process | 3 | 获取FMS服务失败 |
| path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 | | path对应uri不是相册、目录 | Not a directory | 20 | path对应uri不是相册、目录 |
- 示例 **示例:**
```js ```js
// 创建文件,返回文件uri // 创建文件,返回文件uri
...@@ -258,11 +259,15 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac ...@@ -258,11 +259,15 @@ createFile(path : string, filename: string, options? : {dev? : DevInfo}, callbac
let media_path = "" let media_path = ""
// 待保存文件的后缀 // 待保存文件的后缀
let name = "xxx.jpg" let name = "xxx.jpg"
let dev = ""; let options = {
filemanager.createFile(media_path, name, { DevInfo: dev }, function(err, uri) { "dev":{
// 返回uri给应用 "name":"local"
}
};
filemanager.createFile(media_path, name, options, function(err, uri) {
// 返回uri给应用
console.log("file uri:"+uri); console.log("file uri:"+uri);
}); });
``` ```
......
...@@ -2,12 +2,10 @@ ...@@ -2,12 +2,10 @@
> **说明:** > **说明:**
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
>
> API Version 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
## 导入模块 ## 导入模块
``` ```js
import image from '@ohos.multimedia.image'; import image from '@ohos.multimedia.image';
``` ```
...@@ -22,8 +20,8 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi ...@@ -22,8 +20,8 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | ------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| colors | ArrayBuffer | 是 | 颜色数组。 | | colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 |
| options | [InitializetionOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 | | options | [InitializationOptions](#initializationoptions8) | 是 | 创建像素的属性,包括透明度,尺寸,缩略值,像素格式和是否可编辑。 |
**返回值:** **返回值:**
...@@ -34,9 +32,11 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi ...@@ -34,9 +32,11 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions): Promise\<Pi
**示例:** **示例:**
```js ```js
image.createPixelMap(Color, opts) const color = new ArrayBuffer(96);
.then((pixelmap) => { let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
}) image.createPixelMap(color, opts)
.then((pixelmap) => {
})
``` ```
## image.createPixelMap<sup>8+</sup> ## image.createPixelMap<sup>8+</sup>
...@@ -51,15 +51,17 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As ...@@ -51,15 +51,17 @@ createPixelMap(colors: ArrayBuffer, options: InitializationOptions, callback: As
| 名称 | 类型 | 必填 | 说明 | | 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | -------------------------- | | -------- | ------------------------------------------------ | ---- | -------------------------- |
| colors | ArrayBuffer | 是 | 颜色数组。 | | colors | ArrayBuffer | 是 | BGRA_8888格式的颜色数组。 |
| options | [InitializetionOptions](#initializationoptions8) | 是 | 属性。 | | options | [InitializationOptions](#initializationoptions8) | 是 | 属性。 |
| callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 | | callback | AsyncCallback\<[PixelMap](#pixelmap7)> | 是 | 通过回调返回PixelMap对象。 |
**示例:** **示例:**
```js ```js
image.createPixelMap(Color, opts, (pixelmap) => { const color = new ArrayBuffer(96);
}) let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (pixelmap) => {
})
``` ```
## PixelMap<sup>7+</sup> ## PixelMap<sup>7+</sup>
...@@ -68,9 +70,11 @@ image.createPixelMap(Color, opts, (pixelmap) => { ...@@ -68,9 +70,11 @@ image.createPixelMap(Color, opts, (pixelmap) => {
### 属性 ### 属性
| 名称 | 类型 | 可读 | 可写 | 说明 | **系统能力:** SystemCapability.Multimedia.Image
| ----------------------- | ------- | ---- | ---- | ------------------------------------------------------------ |
| isEditable<sup>7+</sup> | boolean | 是 | 否 | 设定是否图像像素可被编辑。<br/>**系统能力:** SystemCapability.Multimedia.Image | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------------------- | ------- | ---- | ---- | -------------------------- |
| isEditable<sup>7+</sup> | boolean | 是 | 否 | 设定是否图像像素可被编辑。 |
### readPixelsToBuffer<sup>7+</sup> ### readPixelsToBuffer<sup>7+</sup>
...@@ -95,11 +99,11 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void> ...@@ -95,11 +99,11 @@ readPixelsToBuffer(dst: ArrayBuffer): Promise\<void>
**示例:** **示例:**
```js ```js
pixelmap.readPixelsToBuffer(readBuffer).then(() => { pixelmap.readPixelsToBuffer(ReadBuffer).then(() => {
//符合条件则进入 console.log('readPixelsToBuffer succeeded.'); //符合条件则进入
}).catch(error => { }).catch(error => {
//不符合条件则进入 console.log('readPixelsToBuffer failed.'); //不符合条件则进入
}) })
``` ```
### readPixelsToBuffer<sup>7+</sup> ### readPixelsToBuffer<sup>7+</sup>
...@@ -120,8 +124,13 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void ...@@ -120,8 +124,13 @@ readPixelsToBuffer(dst: ArrayBuffer, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
pixelmap.readPixelsToBuffer(readBuffer, () => { pixelmap.readPixelsToBuffer(ReadBuffer, (err, res) => {
}) if(err) {
console.log('readPixelsToBuffer failed.'); //不符合条件则进入
} else {
console.log('readPixelsToBuffer succeeded.'); //符合条件则进入
}
})
``` ```
### readPixels<sup>7+</sup> ### readPixels<sup>7+</sup>
...@@ -147,11 +156,11 @@ readPixels(area: PositionArea): Promise\<void> ...@@ -147,11 +156,11 @@ readPixels(area: PositionArea): Promise\<void>
**示例:** **示例:**
```js ```js
pixelmap.readPixels(area).then((data) => { pixelmap.readPixels(Area).then((data) => {
//符合条件则进入 console.log('readPixels succeeded.'); //符合条件则进入
}).catch(error => { }).catch(error => {
//不符合条件则进入 console.log('readPixels failed.'); //不符合条件则进入
}) })
``` ```
### readPixels<sup>7+</sup> ### readPixels<sup>7+</sup>
...@@ -174,19 +183,17 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void ...@@ -174,19 +183,17 @@ readPixels(area: PositionArea, callback: AsyncCallback\<void>): void
```js ```js
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => { image.createPixelMap(color, opts, (err, pixelmap) => {
if(pixelmap == undefined){ if(pixelmap == undefined){
console.info('createPixelMap failed'); console.info('createPixelMap failed.');
expect(false).assertTrue(); } else {
done(); const area = { pixels: new ArrayBuffer(8),
}else{ offset: 0,
const area = { pixels: new ArrayBuffer(8), stride: 8,
offset: 0, region: { size: { height: 1, width: 2 }, x: 0, y: 0 }};
stride: 8, pixelmap.readPixels(area, () => {
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }} console.info('readPixels success');
pixelmap.readPixels(area, () => { })
console.info('readPixels success'); }
})
}
}) })
``` ```
...@@ -218,16 +225,14 @@ let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } ...@@ -218,16 +225,14 @@ let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts) image.createPixelMap(color, opts)
.then( pixelmap => { .then( pixelmap => {
if (pixelmap == undefined) { if (pixelmap == undefined) {
console.info('createPixelMap failed'); console.info('createPixelMap failed.');
expect(false).assertTrue()
done();
} }
const area = { pixels: new ArrayBuffer(8), const area = { pixels: new ArrayBuffer(8),
offset: 0, offset: 0,
stride: 8, stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 } region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
} }
var bufferArr = new Uint8Array(area.pixels); let bufferArr = new Uint8Array(area.pixels);
for (var i = 0; i < bufferArr.length; i++) { for (var i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1; bufferArr[i] = i + 1;
} }
...@@ -240,11 +245,8 @@ image.createPixelMap(color, opts) ...@@ -240,11 +245,8 @@ image.createPixelMap(color, opts)
region: { size: { height: 1, width: 2 }, x: 0, y: 0 } region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
} }
}) })
}) }).catch(error => {
.catch(error => {
console.log('error: ' + error); console.log('error: ' + error);
expect().assertFail();
done();
}) })
``` ```
...@@ -261,19 +263,23 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void ...@@ -261,19 +263,23 @@ writePixels(area: PositionArea, callback: AsyncCallback\<void>): void
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------------------------------ | ---- | ------------------------------ | | --------- | ------------------------------ | ---- | ------------------------------ |
| area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 | | area | [PositionArea](#positionarea7) | 是 | 区域,根据区域写入。 |
| callback: | AsyncCallback\<void> | 是 | 获取回调,失败时返回错误信息。 | | callback: | AsyncCallback\<void> | 是 | 获取回调,失败时error会返回错误信息。 |
**示例:** **示例:**
```js ```js
pixelmap.writePixels(area, () => { pixelmap.writePixels(Area, (error) => {
const readArea = { if (error!=undefined) {
pixels: new ArrayBuffer(20), console.info('writePixels failed.');
offset: 0, } else {
stride: 8, const readArea = {
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }, pixels: new ArrayBuffer(20),
} offset: 0,
}) stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
}
}
})
``` ```
### writeBufferToPixels<sup>7+</sup> ### writeBufferToPixels<sup>7+</sup>
...@@ -299,11 +305,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void> ...@@ -299,11 +305,11 @@ writeBufferToPixels(src: ArrayBuffer): Promise\<void>
**示例:** **示例:**
```js ```js
pixelMap.writeBufferToPixels(colorBuffer).then(() => { PixelMap.writeBufferToPixels(color).then(() => {
console.log("Succeeded in writing data from a buffer to a PixelMap."); console.log("Succeeded in writing data from a buffer to a PixelMap.");
}).catch((err) => { }).catch((err) => {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
}); })
``` ```
### writeBufferToPixels<sup>7+</sup> ### writeBufferToPixels<sup>7+</sup>
...@@ -324,12 +330,13 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void ...@@ -324,12 +330,13 @@ writeBufferToPixels(src: ArrayBuffer, callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
pixelMap.writeBufferToPixels(colorBuffer, function(err) { PixelMap.writeBufferToPixels(color, function(err) {
if (err) { if (err) {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
return; return;
} } else {
console.log("Succeeded in writing data from a buffer to a PixelMap."); console.log("Succeeded in writing data from a buffer to a PixelMap.");
}
}); });
``` ```
...@@ -350,7 +357,7 @@ getImageInfo(): Promise\<ImageInfo> ...@@ -350,7 +357,7 @@ getImageInfo(): Promise\<ImageInfo>
**示例:** **示例:**
```js ```js
pixelMap.getImageInfo().then(function(info) { PixelMap.getImageInfo().then(function(info) {
console.log("Succeeded in obtaining the image pixel map information."); console.log("Succeeded in obtaining the image pixel map information.");
}).catch((err) => { }).catch((err) => {
console.error("Failed to obtain the image pixel map information."); console.error("Failed to obtain the image pixel map information.");
...@@ -374,7 +381,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void ...@@ -374,7 +381,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```js
pixelmap.getImageInfo((imageInfo) => {}) pixelmap.getImageInfo((imageInfo) => {
console.log("getImageInfo succeeded.");
}).catch((err) => {
console.error("getImageInfo failed.");
})
``` ```
### getBytesNumberPerRow<sup>7+</sup> ### getBytesNumberPerRow<sup>7+</sup>
...@@ -394,7 +405,9 @@ getBytesNumberPerRow(): number ...@@ -394,7 +405,9 @@ getBytesNumberPerRow(): number
**示例:** **示例:**
```js ```js
rowCount = pixelmap.getBytesNumberPerRow() image.createPixelMap(clolr, opts, (err,pixelmap) => {
let rowCount = pixelmap.getBytesNumberPerRow();
})
``` ```
### getPixelBytesNumber<sup>7+</sup> ### getPixelBytesNumber<sup>7+</sup>
...@@ -414,7 +427,7 @@ getPixelBytesNumber(): number ...@@ -414,7 +427,7 @@ getPixelBytesNumber(): number
**示例:** **示例:**
```js ```js
pixelBytesNumber = pixelmap.getPixelBytesNumber() let pixelBytesNumber = pixelmap.getPixelBytesNumber();
``` ```
### release<sup>7+</sup> ### release<sup>7+</sup>
...@@ -434,8 +447,13 @@ release():Promise\<void> ...@@ -434,8 +447,13 @@ release():Promise\<void>
**示例:** **示例:**
```js ```js
pixelmap.release().then(() => { }) image.createPixelMap(color, opts, (pixelmap) => {
.catch(error => {}) pixelmap.release().then(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
})
``` ```
### release<sup>7+</sup> ### release<sup>7+</sup>
...@@ -455,7 +473,13 @@ release(callback: AsyncCallback\<void>): void ...@@ -455,7 +473,13 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
pixelmap.release(()=>{ }) image.createPixelMap(color, opts, (pixelmap) => {
pixelmap.release().then(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
})
``` ```
## image.createImageSource ## image.createImageSource
...@@ -508,7 +532,7 @@ createImageSource(fd: number): ImageSource ...@@ -508,7 +532,7 @@ createImageSource(fd: number): ImageSource
**示例:** **示例:**
```js ```js
const imageSourceApi = image.createImageSource(0) const imageSourceApi = image.createImageSource(0);
``` ```
## ImageSource ## ImageSource
...@@ -517,9 +541,11 @@ const imageSourceApi = image.createImageSource(0) ...@@ -517,9 +541,11 @@ const imageSourceApi = image.createImageSource(0)
### 属性 ### 属性
**系统能力:** SystemCapability.Multimedia.Image
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| supportedFormats | Array\<string> | 是 | 否 | 支持的图片格式,包括:png,jpeg,wbmp,bmp,gif,webp,heif等。<br/>**系统能力:** SystemCapability.Multimedia.Image | | supportedFormats | Array\<string> | 是 | 否 | 支持的图片格式,包括:png,jpeg,wbmp,bmp,gif,webp,heif等。 |
### getImageInfo ### getImageInfo
...@@ -539,7 +565,13 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void ...@@ -539,7 +565,13 @@ getImageInfo(index: number, callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```js
imageSourceApi.getImageInfo(0,(error, imageInfo) => {}) imageSourceApi.getImageInfo(0,(error, imageInfo) => {
if(error) {
console.log('getImageInfo failed.');
} else {
console.log('getImageInfo succeeded.');
}
})
``` ```
### getImageInfo ### getImageInfo
...@@ -559,7 +591,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void ...@@ -559,7 +591,11 @@ getImageInfo(callback: AsyncCallback\<ImageInfo>): void
**示例:** **示例:**
```js ```js
imageSourceApi.getImageInfo(imageInfo => {}) imageSourceApi.getImageInfo(imageInfo => {
console.log('getImageInfo succeeded.');
}).catch(error => {
console.log('getImageInfo failed.');
})
``` ```
### getImageInfo ### getImageInfo
...@@ -586,8 +622,11 @@ getImageInfo(index?: number): Promise\<ImageInfo> ...@@ -586,8 +622,11 @@ getImageInfo(index?: number): Promise\<ImageInfo>
```js ```js
imageSourceApi.getImageInfo(0) imageSourceApi.getImageInfo(0)
.then(imageInfo => {}) .then(imageInfo => {
.catch(error => {}) console.log('getImageInfo succeeded.');
}).catch(error => {
console.log('getImageInfo failed.');
})
``` ```
### getImageProperty<sup>7+</sup> ### getImageProperty<sup>7+</sup>
...@@ -615,8 +654,11 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string ...@@ -615,8 +654,11 @@ getImageProperty(key:string, options?: GetImagePropertyOptions): Promise\<string
```js ```js
imageSourceApi.getImageProperty("BitsPerSample") imageSourceApi.getImageProperty("BitsPerSample")
.then(data => {}) .then(data => {
.catch(error => {}) console.log('getImageProperty succeeded.');
}).catch(error => {
console.log('getImageProperty failed.');
})
``` ```
### getImageProperty<sup>7+</sup> ### getImageProperty<sup>7+</sup>
...@@ -637,7 +679,13 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void ...@@ -637,7 +679,13 @@ getImageProperty(key:string, callback: AsyncCallback\<string>): void
**示例:** **示例:**
```js ```js
imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {}) imageSourceApi.getImageProperty("BitsPerSample",(error,data) => {
if(error) {
console.log('getImageProperty failed.');
} else {
console.log('getImageProperty succeeded.');
}
})
``` ```
### getImageProperty<sup>7+</sup> ### getImageProperty<sup>7+</sup>
...@@ -659,7 +707,13 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa ...@@ -659,7 +707,13 @@ getImageProperty(key:string, options: GetImagePropertyOptions, callback: AsyncCa
**示例:** **示例:**
```js ```js
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {}) imageSourceApi.getImageProperty("BitsPerSample",Property,(error,data) => {
if(error) {
console.log('getImageProperty failed.');
} else {
console.log('getImageProperty succeeded.');
}
})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
...@@ -685,8 +739,11 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap> ...@@ -685,8 +739,11 @@ createPixelMap(options?: DecodingOptions): Promise\<PixelMap>
**示例:** **示例:**
```js ```js
imageSourceApi.createPixelMap().then(pixelmap => {}) imageSourceApi.createPixelMap().then(pixelmap => {
.catch(error => {}) console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
...@@ -706,7 +763,11 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void ...@@ -706,7 +763,11 @@ createPixelMap(callback: AsyncCallback\<PixelMap>): void
**示例:** **示例:**
```js ```js
imageSourceApi.createPixelMap(pixelmap => {}) imageSourceApi.createPixelMap(pixelmap => {
console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
...@@ -727,7 +788,11 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo ...@@ -727,7 +788,11 @@ createPixelMap(options: DecodingOptions, callback: AsyncCallback\<PixelMap>): vo
**示例:** **示例:**
```js ```js
imageSourceApi.createPixelMap(decodingOptions, pixelmap => {}) imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.log('createPixelMap succeeded.');
}).catch(error => {
console.log('createPixelMap failed.');
})
``` ```
### release ### release
...@@ -747,7 +812,11 @@ release(callback: AsyncCallback\<void>): void ...@@ -747,7 +812,11 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
imageSourceApi.release(() => {}) imageSourceApi.release(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
``` ```
### release ### release
...@@ -767,7 +836,11 @@ release(): Promise\<void> ...@@ -767,7 +836,11 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
imageSourceApi.release().then(()=>{ }).catch(error => {}) imageSourceApi.release().then(()=>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
``` ```
## image.createImagePacker ## image.createImagePacker
...@@ -796,9 +869,11 @@ const imagePackerApi = image.createImagePacker(); ...@@ -796,9 +869,11 @@ const imagePackerApi = image.createImagePacker();
### 属性 ### 属性
| 名称 | 类型 | 可读 | 可写 | 说明 | **系统能力:** SystemCapability.Multimedia.Image
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| supportedFormats | Array\<string> | 是 | 否 | 图片打包支持的格式,jpeg。<br/>**系统能力:** SystemCapability.Multimedia.Image | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ---------------- | -------------- | ---- | ---- | -------------------------- |
| supportedFormats | Array\<string> | 是 | 否 | 图片打包支持的格式,jpeg。 |
### packing ### packing
...@@ -814,13 +889,13 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr ...@@ -814,13 +889,13 @@ packing(source: ImageSource, option: PackingOption, callback: AsyncCallback\<Arr
| -------- | ---------------------------------- | ---- | ---------------------------------- | | -------- | ---------------------------------- | ---- | ---------------------------------- |
| source | [ImageSource](#imagesource) | 是 | 打包的图片源。 | | source | [ImageSource](#imagesource) | 是 | 打包的图片源。 |
| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | | option | [PackingOption](#packingoption) | 是 | 设置打包参数。 |
| callback | AsyncCallback\<ArrayBuffer> | 是 | 获取图片打包回调,返回打包后数据。 | | callback | AsyncCallback\<ArrayBuffer> | 是 | 获取图片打包回调,返回打包后数据。 |
**示例:** **示例:**
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:"image/jpeg", quality:98 };
imagePackerApi.packing(imageSourceApi, packOpts, data => {}) imagePackerApi.packing(ImageSourceApi, packOpts, data => {})
``` ```
### packing ### packing
...@@ -848,9 +923,12 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer> ...@@ -848,9 +923,12 @@ packing(source: ImageSource, option: PackingOption): Promise\<ArrayBuffer>
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(ImageSourceApi, packOpts)
.then( data => { }) .then( data => {
.catch(error => {}) console.log('packing succeeded.');
}).catch(error => {
console.log('packing failed.');
})
``` ```
### packing<sup>8+</sup> ### packing<sup>8+</sup>
...@@ -873,7 +951,11 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB ...@@ -873,7 +951,11 @@ packing(source: PixelMap, option: PackingOption, callback: AsyncCallback\<ArrayB
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(pixelMapApi, packOpts, data => {}) imagePackerApi.packing(PixelMapApi, packOpts, data => {
console.log('packing succeeded.');
}).catch(error => {
console.log('packing failed.');
})
``` ```
### packing<sup>8+</sup> ### packing<sup>8+</sup>
...@@ -886,10 +968,10 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> ...@@ -886,10 +968,10 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ------ | ------------------------------- | ---- | -------------- | | ------ | ------------------------------- | ---- | ------------------ |
| source | [PixelMap](#pixelmap) | 是 | 打包的PixelMap源。 | | source | [PixelMap](#pixelmap) | 是 | 打包的PixelMap源。 |
| option | [PackingOption](#packingoption) | 是 | 设置打包参数。 | | option | [PackingOption](#packingoption) | 是 | 设置打包参数。 |
**返回值:** **返回值:**
...@@ -901,9 +983,12 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer> ...@@ -901,9 +983,12 @@ packing(source: PixelMap, option: PackingOption): Promise\<ArrayBuffer>
```js ```js
let packOpts = { format:["image/jpeg"], quality:98 } let packOpts = { format:["image/jpeg"], quality:98 }
imagePackerApi.packing(pixelMapApi, packOpts) imagePackerApi.packing(PixelMapApi, packOpts)
.then( data => { }) .then( data => {
.catch(error => {}) console.log('packing succeeded.');
}).catch(error => {
console.log('packing failed.');
})
``` ```
### release ### release
...@@ -923,7 +1008,11 @@ release(callback: AsyncCallback\<void>): void ...@@ -923,7 +1008,11 @@ release(callback: AsyncCallback\<void>): void
**示例:** **示例:**
```js ```js
imagePackerApi.release(()=>{}) imagePackerApi.release(()=>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
``` ```
### release ### release
...@@ -943,8 +1032,390 @@ release(): Promise\<void> ...@@ -943,8 +1032,390 @@ release(): Promise\<void>
**示例:** **示例:**
```js ```js
imagePackerApi.release().then(()=>{ imagePackerApi.release().then(()=>{
}).catch((error)=>{}) console.log('release succeeded.');
}).catch((error)=>{
console.log('release failed.');
})
```
## image.createImageReceiver<sup>9+</sup>
createImageReceiver(width: number, height: number, format: number, capacity: number): ImageReceiver
通过宽、高、图片格式、容量创建ImageReceiver实例。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---------------------- |
| width | number | 是 | 图像的默认宽度。 |
| height | number | 是 | 图像的默认高度。 |
| format | number | 是 | 图像格式。 |
| capacity | number | 是 | 同时访问的最大图像数。 |
**返回值:**
| 类型 | 说明 |
| -------------------------------- | --------------------------------------- |
| [ImageReceiver](#imagereceiver9) | 如果操作成功,则返回ImageReceiver实例。 |
**示例:**
```js
var receiver = image.createImageReceiver(8192, 8, 4, 8);
```
## ImageReceiver<sup>9+</sup>
图像接收类,用于获取组件surface id,接收最新的图片和读取下一张图片,以及释放ImageReceiver实例。
在调用以下方法前需要先创建ImageReceiver实例。
### 属性
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver
| 名称 | 类型 | 可读 | 可写 | 说明 |
| --------------------- | ---------------------------- | ---- | ---- | ------------------ |
| size<sup>9+</sup> | [Size](#size) | 是 | 否 | 图片大小。 |
| capacity<sup>9+</sup> | number | 是 | 否 | 同时访问的图像数。 |
| format<sup>9+</sup> | [ImageFormat](#imageformat9) | 是 | 否 | 图像格式。 |
### getReceivingSurfaceId<sup>9+</sup>
getReceivingSurfaceId(callback: AsyncCallback\<string>): void
用于获取一个surface id供Camera或其他组件使用。使用callback返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ---------------------- | ---- | -------------------------- |
| callback | AsyncCallback\<string> | 是 | 回调函数,返回surface id。 |
**示例:**
```js
receiver.getReceivingSurfaceId((err, id) => {
if(err) {
console.log('getReceivingSurfaceId failed.');
} else {
console.log('getReceivingSurfaceId succeeded.');
}
});
```
### getReceivingSurfaceId<sup>9+</sup>
getReceivingSurfaceId(): Promise\<string>
用于获取一个surface id供Camera或其他组件使用。使用promise返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**返回值:**
| 类型 | 说明 |
| ---------------- | -------------------- |
| Promise\<string> | 异步返回surface id。 |
**示例:**
```js
receiver.getReceivingSurfaceId().then( id => {
console.log('getReceivingSurfaceId succeeded.');
}).catch(error => {
console.log('getReceivingSurfaceId failed.');
})
```
### readLatestImage<sup>9+</sup>
readLatestImage(callback: AsyncCallback\<Image>): void
从ImageReceiver读取最新的图片,并使用callback返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | ------------------------ |
| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,返回最新图像。 |
**示例:**
```js
receiver.readLatestImage((err, img) => {
if(err) {
console.log('readLatestImage failed.');
} else {
console.log('readLatestImage succeeded.');
}
});
```
### readLatestImage<sup>9+</sup>
readLatestImage(): Promise\<Image>
从ImageReceiver读取最新的图片,并使用promise返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**返回值:**
| 类型 | 说明 |
| ------------------------- | ------------------ |
| Promise<[Image](#image8)> | 异步返回最新图片。 |
**示例:**
```js
receiver.readLatestImage().then(img => {
console.log('readLatestImage succeeded.');
}).catch(error => {
console.log('readLatestImage failed.');
})
```
### readNextImage<sup>9+</sup>
readNextImage(callback: AsyncCallback\<Image>): void
从ImageReceiver读取下一张图片,并使用callback返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | ------------------------------- | ---- | -------------------------- |
| callback | AsyncCallback<[Image](#image9)> | 是 | 回调函数,返回下一张图片。 |
**示例:**
```js
receiver.readNextImage((err, img) => {
if(err) {
console.log('readNextImage failed.');
} else {
console.log('readNextImage succeeded.');
}
});
```
### readNextImage<sup>9+</sup>
readNextImage(): Promise\<Image>
从ImageReceiver读取下一张图片,并使用promise返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**返回值:**
| 类型 | 说明 |
| ------------------------- | -------------------- |
| Promise<[Image](#image9)> | 异步返回下一张图片。 |
**示例:**
```js
receiver.readNextImage().then(img => {
console.log('readNextImage succeeded.');
}).catch(error => {
console.log('readNextImage failed.');
})
```
### on('imageArrival')<sup>9+</sup>
on(type: 'imageArrival', callback: AsyncCallback\<void>): void
接收图片时注册回调。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------------------------------------ |
| type | string | 是 | 注册事件的类型,固定为'imageArrival',接收图片时触发。 |
| callback | AsyncCallback\<void> | 是 | 注册的事件回调。 |
**示例:**
```js
receiver.on('imageArrival', () => {})
```
### release<sup>9+</sup>
release(callback: AsyncCallback\<void>): void
释放ImageReceiver实例并使用回调返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | ------------------------ |
| callback | AsyncCallback\<void> | 是 | 回调函数,返回操作结果。 |
**示例:**
```js
receiver.release(() => {})
```
### release<sup>9+</sup>
release(): Promise\<void>
释放ImageReceiver实例并使用promise返回结果。
**系统能力:** SystemCapability.Multimedia.Image.ImageReceiver
**返回值:**
| 类型 | 说明 |
| -------------- | ------------------ |
| Promise\<void> | 异步返回操作结果。 |
**示例:**
```js
receiver.release().then(() => {
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
```
## Image<sup>9+</sup>
提供基本的图像操作,包括获取图像信息、读写图像数据。调用[readNextImage](#readnextimage9)[readLatestImage](#readlatestimage9)接口时会返回image。
### 属性
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| --------------------- | ------------------ | ---- | ---- | -------------------------------------------------- |
| clipRect<sup>9+</sup> | [Region](#region7) | 是 | 是 | 要裁剪的图像区域。 |
| size<sup>9+</sup> | [Size](#size) | 是 | 否 | 图像大小。 |
| format<sup>9+</sup> | number | 是 | 否 | 图像格式,参考[PixelMapFormat](#pixelmapformat7)。 |
### getComponent<sup>9+</sup>
getComponent(componentType: ComponentType, callback: AsyncCallback\<Component>): void
根据图像的组件类型从图像中获取组件缓存并使用callback返回结果。
**系统能力:** SystemCapability.Multimedia.Image.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | --------------------------------------- | ---- | -------------------- |
| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。 |
| callback | AsyncCallback<[Component](#component9)> | 是 | 用于返回组件缓冲区。 |
**示例:**
```js
img.getComponent(4, (err, component) => {
if(err) {
console.log('getComponent failed.');
} else {
console.log('getComponent succeeded.');
}
})
```
### getComponent<sup>9+</sup>
getComponent(componentType: ComponentType): Promise\<Component>
根据图像的组件类型从图像中获取组件缓存并使用Promise方式返回结果。
**系统能力:** SystemCapability.Multimedia.Image.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| ------------- | -------------------------------- | ---- | ---------------- |
| componentType | [ComponentType](#componenttype9) | 是 | 图像的组件类型。 |
**返回值:**
| 类型 | 说明 |
| --------------------------------- | --------------------------------- |
| Promise<[Component](#component9)> | 用于返回组件缓冲区的promise实例。 |
**示例:**
```js
img.getComponent(4).then(component => { })
```
### release<sup>9+</sup>
release(callback: AsyncCallback\<void>): void
释放当前图像并使用callback返回结果。
在接收另一个图像前必须先释放对应资源。
**系统能力:** SystemCapability.Multimedia.Image.Core
**参数:**
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------------------- | ---- | -------------- |
| callback | AsyncCallback\<void> | 是 | 返回操作结果。 |
**示例:**
```js
img.release(() =>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
```
### release<sup>9+</sup>
release(): Promise\<void>
释放当前图像并使用Promise方式返回结果。
在接收另一个图像前必须先释放对应资源。
**系统能力:** SystemCapability.Multimedia.Image.Core
**返回值:**
| 类型 | 说明 |
| -------------- | --------------------- |
| Promise\<void> | promise返回操作结果。 |
**示例:**
```js
img.release().then(() =>{
console.log('release succeeded.');
}).catch(error => {
console.log('release failed.');
})
``` ```
## PositionArea<sup>7+</sup> ## PositionArea<sup>7+</sup>
...@@ -957,7 +1428,7 @@ release(): Promise\<void> ...@@ -957,7 +1428,7 @@ release(): Promise\<void>
| ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ | | ------ | ------------------ | ---- | ---- | ------------------------------------------------------------ |
| pixels | ArrayBuffer | 是 | 否 | 像素。 | | pixels | ArrayBuffer | 是 | 否 | 像素。 |
| offset | number | 是 | 否 | 偏移量。 | | offset | number | 是 | 否 | 偏移量。 |
| stride | number | 是 | 否 | 像素间距,stride >= region.size.width*4。 | | stride | number | 是 | 否 | 像素间距,stride >= region.size.width*4。 |
| region | [Region](#region7) | 是 | 否 | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度 | | region | [Region](#region7) | 是 | 否 | 区域,按照区域读写。写入的区域宽度加X坐标不能大于原图的宽度,写入的区域高度加Y坐标不能大于原图的高度 |
## ImageInfo ## ImageInfo
...@@ -983,7 +1454,7 @@ release(): Promise\<void> ...@@ -983,7 +1454,7 @@ release(): Promise\<void>
## PixelMapFormat<sup>7+</sup> ## PixelMapFormat<sup>7+</sup>
枚举,像素格式。 枚举,图片像素格式。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
...@@ -995,7 +1466,7 @@ release(): Promise\<void> ...@@ -995,7 +1466,7 @@ release(): Promise\<void>
## AlphaType<sup>9+</sup> ## AlphaType<sup>9+</sup>
枚举,透明度 枚举,图像的透明度类型
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
...@@ -1008,7 +1479,7 @@ release(): Promise\<void> ...@@ -1008,7 +1479,7 @@ release(): Promise\<void>
## ScaleMode<sup>9+</sup> ## ScaleMode<sup>9+</sup>
枚举,缩略值 枚举,图像的缩放模式
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
...@@ -1019,19 +1490,21 @@ release(): Promise\<void> ...@@ -1019,19 +1490,21 @@ release(): Promise\<void>
## InitializationOptions<sup>8+</sup> ## InitializationOptions<sup>8+</sup>
PixelMap的初始化选项。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ----------- | ---------------------------------- | ---- | ---- | -------------- | | ---------------------- | ---------------------------------- | ---- | ---- | -------------- |
| alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 | | alphaType<sup>9+</sup> | [AlphaType](#alphatype9) | 是 | 是 | 透明度。 |
| editable | boolean | 是 | 是 | 是否可编辑。 | | editable | boolean | 是 | 是 | 是否可编辑。 |
| pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 | | pixelFormat | [PixelMapFormat](#pixelmapformat7) | 是 | 是 | 像素格式。 |
| scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 | | scaleMode<sup>9+</sup> | [ScaleMode](#scalemode9) | 是 | 是 | 缩略值。 |
| size | [Size](#size) | 是 | 是 | 创建图片大小。 | | size | [Size](#size) | 是 | 是 | 创建图片大小。 |
## DecodingOptions<sup>7+</sup> ## DecodingOptions<sup>7+</sup>
解码设置选项。 图像解码设置选项。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image **系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image
...@@ -1066,7 +1539,7 @@ release(): Promise\<void> ...@@ -1066,7 +1539,7 @@ release(): Promise\<void>
| 名称 | 类型 | 可读 | 可写 | 说明 | | 名称 | 类型 | 可读 | 可写 | 说明 |
| ------- | ------ | ---- | ---- | -------------- | | ------- | ------ | ---- | ---- | -------------- |
| format | string | 是 | 是 | 目标格式。 | | format | string | 是 | 是 | 目标格式。 |
| quality | number | 是 | 是 | 目标图片质量。 | | quality | number | 是 | 是 | JPEG编码中设定输出图片质量的参数,取值范围为1-100。 |
## GetImagePropertyOptions<sup>7+</sup> ## GetImagePropertyOptions<sup>7+</sup>
...@@ -1096,3 +1569,40 @@ release(): Promise\<void> ...@@ -1096,3 +1569,40 @@ release(): Promise\<void>
| GPS_LATITUDE_REF | "GPSLatitudeRef" | 纬度引用,例如N或S。 | | GPS_LATITUDE_REF | "GPSLatitudeRef" | 纬度引用,例如N或S。 |
| GPS_LONGITUDE_REF | "GPSLongitudeRef" | 经度引用,例如W或E。 | | GPS_LONGITUDE_REF | "GPSLongitudeRef" | 经度引用,例如W或E。 |
## ImageFormat<sup>9+</sup>
枚举,图片格式。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
| 名称 | 默认值 | 描述 |
| ------------ | ------ | -------------------- |
| YCBCR_422_SP | 1000 | YCBCR422半平面格式。 |
| JPEG | 2000 | JPEG编码格式。 |
## ComponentType<sup>9+</sup>
枚举,图像的组件类型。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.ImageReceiver
| 名称 | 默认值 | 描述 |
| ----- | ------ | ----------- |
| YUV_Y | 1 | 亮度信息。 |
| YUV_U | 2 | 色度信息。 |
| YUV_V | 3 | 色度信息。 |
| JPEG | 4 | Jpeg 类型。 |
## Component<sup>9+</sup>
描述图像颜色分量。
**系统能力:** 以下各项对应的系统能力均为SystemCapability.Multimedia.Image.Core
| 名称 | 类型 | 可读 | 可写 | 说明 |
| ------------- | -------------------------------- | ---- | ---- | ------------ |
| componentType | [ComponentType](#componenttype9) | 是 | 否 | 组件类型。 |
| rowStride | number | 是 | 否 | 行距。 |
| pixelStride | number | 是 | 否 | 像素间距。 |
| byteBuffer | ArrayBuffer | 是 | 否 | 组件缓冲区。 |
# 数据标签 # 数据标签
该模块提供文件数据安全等级的相关功能:向应用程序提供查询、设置文件数据安全等级的JS接口。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件数据安全等级的相关功能:向应用程序提供查询、设置文件数据安全等级的JS接口。
## 导入模块 ## 导入模块
```js ```js
......
# statfs # statfs
该模块提供文件系统相关存储信息的功能,向应用程序提供获取文件系统总字节数、空闲字节数的JS接口。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
该模块提供文件系统相关存储信息的功能,向应用程序提供获取文件系统总字节数、空闲字节数的JS接口。
## 导入模块 ## 导入模块
```js ```js
......
# 应用空间统计 # 应用空间统计
该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> >
> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 > - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
## 导入模块 ## 导入模块
```js ```js
import storageStatistics from "@ohos.storageStatistics"; import storageStatistics from "@ohos.storageStatistics";
``` ```
## storagestatistics.getTotalSizeOfVolume ## storageStatistics.getTotalSizeOfVolume
getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
...@@ -23,32 +23,34 @@ getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; ...@@ -23,32 +23,34 @@ getTotalSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- | | ---------- | ------ | ---- | ---- |
| volumeUuid | string | 是 | 卷id | | volumeUuid | string | 是 | 卷id |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------- | | --------------------- | ---------------- |
| Promise&lt;number&gt; | 返回指定卷总空间 | | Promise&lt;number&gt; | 返回指定卷总空间 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getTotalSizeOfVolume(uuid).then(function(number){ storageStatistics.getTotalSizeOfVolume(uuid).then(function(number){
console.info("getTotalSizeOfVolume successfully:"+ number); console.info("getTotalSizeOfVolume successfully:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("getTotalSizeOfVolume failed with error:"+ err); console.info("getTotalSizeOfVolume failed with error:"+ err);
}); });
``` ```
## storagestatistics.getTotalSizeOfVolume ## storageStatistics.getTotalSizeOfVolume
getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void
...@@ -58,28 +60,28 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):v ...@@ -58,28 +60,28 @@ getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):v
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- | | ---------- | ------------------------------------ | ---- | -------------------------- |
| volumeUuid | string | 是 | 卷id | | volumeUuid | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取指定卷总空间之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取指定卷总空间之后的回调 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getTotalSizeOfVolume(uuid, function(error, number){ storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){
// do something // do something
console.info("getTotalSizeOfVolume successfully:"+ number); console.info("getTotalSizeOfVolume successfully:"+ number);
}); });
``` ```
## storagestatistics.getFreeSizeOfVolume ## storageStatistics.getFreeSizeOfVolume
getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
...@@ -89,25 +91,27 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; ...@@ -89,25 +91,27 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- | | ---------- | ------ | ---- | ---- |
| volumeUuid | string | 是 | 卷id | | volumeUuid | string | 是 | 卷id |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------ | | --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回指定卷可用空间 | | Promise&lt;number&gt; | 返回指定卷可用空间 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getFreeSizeOfVolume(uuid).then(function(number){ storageStatistics.getFreeSizeOfVolume(uuid).then(function(number){
console.info("getFreeSizeOfVolume successfully:"+ number); console.info("getFreeSizeOfVolume successfully:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("getFreeSizeOfVolume failed with error:"+ err); console.info("getFreeSizeOfVolume failed with error:"+ err);
...@@ -115,7 +119,7 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt; ...@@ -115,7 +119,7 @@ getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
``` ```
## storagestatistics.getFreeSizeOfVolume ## storageStatistics.getFreeSizeOfVolume
getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):void
...@@ -125,26 +129,28 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):vo ...@@ -125,26 +129,28 @@ getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback&lt;number&gt;):vo
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | ---------------------------- | | ---------- | ------------------------------------ | ---- | ---------------------------- |
| volumeUuid | string | 是 | 卷id | | volumeUuid | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取指定卷可用空间之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取指定卷可用空间之后的回调 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
storagestatistics.getFreeSizeOfVolume(uuid, function(error, number){ storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){
// do something // do something
console.info("getFreeSizeOfVolume successfully:"+ number); console.info("getFreeSizeOfVolume successfully:"+ number);
}); });
``` ```
## storagestatistics.getBundleStats<sup>9+</sup> ## storageStatistics.getBundleStats<sup>9+</sup>
getBundleStats(packageName: string): Promise&lt;BundleStats&gt; getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
...@@ -154,32 +160,34 @@ getBundleStats(packageName: string): Promise&lt;BundleStats&gt; ...@@ -154,32 +160,34 @@ getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | -------- | | ----------- | ------ | ---- | -------- |
| packageName | string | 是 | 应用包名 | | packageName | string | 是 | 应用包名 |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------------ | -------------------------- | | ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | 返回指定卷上的应用存储数据 | | Promise&lt;[Bundlestats](#bundlestats)&gt; | 返回指定卷上的应用存储数据 |
- 示例 **示例:**
```js ```js
let packageName = ""; let packageName = "";
storagestatistics.getBundleStats(packageName).then(function(BundleStats){ storageStatistics.getBundleStats(packageName).then(function(BundleStats){
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats)); console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
}).catch(function(err){ }).catch(function(err){
console.info("getBundleStats failed with error:"+ err); console.info("getBundleStats failed with error:"+ err);
}); });
``` ```
## storagestatistics.getBundleStats<sup>9+</sup> ## storageStatistics.getBundleStats<sup>9+</sup>
getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void
...@@ -189,28 +197,28 @@ getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;) ...@@ -189,28 +197,28 @@ getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;)
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ | | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | 是 | 应用包名 | | packageName | string | 是 | 应用包名 |
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | 是 | 获取指定卷上的应用存储数据之后的回调 | | callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | 是 | 获取指定卷上的应用存储数据之后的回调 |
- 示例 **示例:**
```js ```js
let packageName = ""; let packageName = "";
storagestatistics.getBundleStats(packageName, function(error, BundleStats){ storageStatistics.getBundleStats(packageName, function(error, BundleStats){
// do something // do something
console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats)); console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
}); });
``` ```
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
## storagestatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(): Promise&lt;BundleStats&gt; getCurrentBundleStats(): Promise&lt;BundleStats&gt;
...@@ -218,50 +226,51 @@ getCurrentBundleStats(): Promise&lt;BundleStats&gt; ...@@ -218,50 +226,51 @@ getCurrentBundleStats(): Promise&lt;BundleStats&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ------------------------------------------ | -------------------------- | | ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | 返回指定卷上的应用存储状态 | | Promise&lt;[Bundlestats](#bundlestats)&gt; | 返回指定卷上的应用存储状态 |
- 示例 **示例:**
```js ```js
let bundleStats = storageStatistics.getCurrentBundleStats(); let bundleStats = storageStatistics.getCurrentBundleStats();
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
``` ```
## storagestatistics.getCurrentBundleStats<sup>9+</sup> ## storageStatistics.getCurrentBundleStats<sup>9+</sup>
getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
第三方应用异步获取占用空间,以callback方式返回。 第三方应用异步获取占用空间,以callback方式返回。
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ | | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| callback | callback:AsyncCallback&lt;[BundleStats](#bundlestats)&gt; | 是 | 获取指定卷上的应用存储状态之后的回调 | | callback | callback:AsyncCallback&lt;[BundleStats](#bundlestats)&gt; | 是 | 获取指定卷上的应用存储状态之后的回调 |
- 示例 **示例:**
```js ```js
storagestatistics.getCurrentBundleStats(function(error, bundleStats){ storageStatistics.getCurrentBundleStats(function(error, bundleStats){
// do something // do something
console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
}); });
``` ```
## BundleStats<sup>9+</sup> ## BundleStats<sup>9+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。<br> **系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 属性
### 属性
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| --------- | ------ | -------------- | | --------- | ------ | -------------- |
...@@ -270,9 +279,7 @@ getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void ...@@ -270,9 +279,7 @@ getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
| dataSize | number | 应用总数据大小 | | dataSize | number | 应用总数据大小 |
## storageStatistics.getTotalSize<sup>9+</sup>
## storagestatistics.getTotalSize<sup>9+</sup>
getTotalSize(): Promise&lt;number&gt; getTotalSize(): Promise&lt;number&gt;
...@@ -282,22 +289,24 @@ getTotalSize(): Promise&lt;number&gt; ...@@ -282,22 +289,24 @@ getTotalSize(): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 返回值
**返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------ | | --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回内卡的总空间大小 | | Promise&lt;number&gt; | 返回内卡的总空间大小 |
- 示例 **示例:**
```js ```js
let number = storageStatistics.getTotalSize(); let number = storageStatistics.getTotalSize();
console.info("getTotalSize successfully:"+ JSON.stringify(number)); console.info("getTotalSize successfully:"+ JSON.stringify(number));
``` ```
## storagestatistics.getTotalSize<sup>9+</sup> ## storageStatistics.getTotalSize<sup>9+</sup>
getTotalSize(callback: AsyncCallback&lt;number&gt;): void getTotalSize(callback: AsyncCallback&lt;number&gt;): void
...@@ -307,25 +316,27 @@ getTotalSize(callback: AsyncCallback&lt;number&gt;): void ...@@ -307,25 +316,27 @@ getTotalSize(callback: AsyncCallback&lt;number&gt;): void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------ | | -------- | ------------------------------------ | ---- | ------------------------ |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取内卡的总空间大小之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取内卡的总空间大小之后的回调 |
- 示例 **示例:**
```js ```js
storagestatistics.getTotalSize(function(error, number){ storageStatistics.getTotalSize(function(error, number){
// do something // do something
console.info("getTotalSize successfully:"+ JSON.stringify(number)); console.info("getTotalSize successfully:"+ JSON.stringify(number));
}); });
``` ```
## storagestatistics.getFreeSize<sup>9+</sup> ## storageStatistics.getFreeSize<sup>9+</sup>
getFreeSize(): Promise&lt;number&gt; getFreeSize(): Promise&lt;number&gt;
...@@ -335,23 +346,25 @@ getFreeSize(): Promise&lt;number&gt; ...@@ -335,23 +346,25 @@ getFreeSize(): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 返回值
**返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ------------------ | | --------------------- | ------------------ |
| Promise&lt;number&gt; | 返回内卡的可用空间大小 | | Promise&lt;number&gt; | 返回内卡的可用空间大小 |
- 示例 **示例:**
```js ```js
let number = storageStatistics.getFreeSize(); let number = storageStatistics.getFreeSize();
console.info("getFreeSize successfully:"+ JSON.stringify(number)); console.info("getFreeSize successfully:"+ JSON.stringify(number));
``` ```
## storagestatistics.getFreeSize<sup>9+</sup> ## storageStatistics.getFreeSize<sup>9+</sup>
getFreeSize(callback: AsyncCallback&lt;number&gt;): void getFreeSize(callback: AsyncCallback&lt;number&gt;): void
...@@ -361,26 +374,26 @@ getFreeSize(callback: AsyncCallback&lt;number&gt;): void ...@@ -361,26 +374,26 @@ getFreeSize(callback: AsyncCallback&lt;number&gt;): void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------ | ---- | ------------------------- | | -------- | ------------------------------------ | ---- | ------------------------- |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取内卡的可用空间大小之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取内卡的可用空间大小之后的回调 |
- 示例 **示例:**
```js ```js
storagestatistics.getFreeSize(function(error, number){ storageStatistics.getFreeSize(function(error, number){
// do something // do something
console.info("getFreeSize successfully:"+ JSON.stringify(number)); console.info("getFreeSize successfully:"+ JSON.stringify(number));
}); });
``` ```
## storageStatistics.getSystemSize<sup>9+</sup>
## storagestatistics.getSystemSize<sup>9+</sup>
getSystemSize(): Promise&lt;number&gt; getSystemSize(): Promise&lt;number&gt;
...@@ -390,25 +403,27 @@ getSystemSize(): Promise&lt;number&gt; ...@@ -390,25 +403,27 @@ getSystemSize(): Promise&lt;number&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 返回值
**返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------- | | --------------------- | ---------------- |
| Promise&lt;number&gt; | 返回系统空间大小 | | Promise&lt;number&gt; | 返回系统空间大小 |
- 示例 **示例:**
```js ```js
storagestatistics.getSystemSize().then(function(number){ storageStatistics.getSystemSize().then(function(number){
console.info("getSystemSize successfully:"+ number); console.info("getSystemSize successfully:"+ number);
}).catch(function(err){ }).catch(function(err){
console.info("getSystemSize failed with error:"+ err); console.info("getSystemSize failed with error:"+ err);
}); });
``` ```
## storagestatistics.getSystemSize<sup>9+</sup> ## storageStatistics.getSystemSize<sup>9+</sup>
getSystemSize(callback:AsyncCallback&lt;number&gt;):void getSystemSize(callback:AsyncCallback&lt;number&gt;):void
...@@ -418,28 +433,28 @@ getSystemSize(callback:AsyncCallback&lt;number&gt;):void ...@@ -418,28 +433,28 @@ getSystemSize(callback:AsyncCallback&lt;number&gt;):void
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- | | ---------- | ------------------------------------ | ---- | -------------------------- |
| callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取系统空间大小之后的回调 | | callback | callback:AsyncCallback&lt;number&gt; | 是 | 获取系统空间大小之后的回调 |
- 示例 **示例:**
```js ```js
storagestatistics.getSystemSize(function(error, number){ storageStatistics.getSystemSize(function(error, number){
// do something // do something
console.info("getSystemSize successfully:"+ number); console.info("getSystemSize successfully:"+ number);
}); });
``` ```
## storagestatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId: number): Promise&lt;StorageStats&gt; ## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId? : number): Promise&lt;StorageStats&gt;
异步获取用户各类别数据大小,以promise方式返回。 异步获取用户各类别数据大小,以promise方式返回。
...@@ -447,32 +462,34 @@ getUserStorageStats(userId: number): Promise&lt;StorageStats&gt; ...@@ -447,32 +462,34 @@ getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------ | ---- | ---- | | ---------- | ------ | ---- | ---- |
| userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。| | userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。|
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ---------------- | | --------------------- | ---------------- |
| Promise&lt;[StorageStats](#StorageStats)&gt; | 返回各类别数据大小 | | Promise&lt;[StorageStats](#StorageStats)&gt; | 返回各类别数据大小 |
- 示例 **示例:**
```js ```js
let userId = ""; let userId = "";
storagestatistics.getUserStorageStats(userId).then(function(StorageStats){ storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}).catch(function(err){ }).catch(function(err){
console.info("getUserStorageStats failed with error:"+ err); console.info("getUserStorageStats failed with error:"+ err);
}); });
``` ```
## storagestatistics.getUserStorageStats<sup>9+</sup> ## storageStatistics.getUserStorageStats<sup>9+</sup>
getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;):void getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;):void
...@@ -482,32 +499,37 @@ getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;): ...@@ -482,32 +499,37 @@ getUserStorageStats(userId: number, callback:AsyncCallback&lt;StorageStats&gt;):
**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics **系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 参数
**参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | ------------------------------------ | ---- | -------------------------- | | ---------- | ------------------------------------ | ---- | -------------------------- |
| userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。 | | userId | string | 否 | 用户id <br/>确认当前用户:<br/>-&nbsp;有值:表示指定用户。<br/>-&nbsp;无值:表示当前用户。 |
| callback | callback:AsyncCallback&lt;[StorageStats](#StorageStats)&gt; | 是 | 返回各类别数据大小之后的回调 | | callback | callback:AsyncCallback&lt;[StorageStats](#StorageStats)&gt; | 是 | 返回各类别数据大小之后的回调 |
- 示例 **示例:**
```js ```js
let userId = ""; let userId = "";
storagestatistics.getUserStorageStats(userId, function(error, StorageStats){ storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
// do something // do something
console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
}); });
``` ```
## StorageStats<sup>9+</sup> ## StorageStats<sup>9+</sup>
**系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics。<br> **系统能力**:以下各项对应的系统能力均为SystemCapability.FileManagement.StorageService.SpatialStatistics
该接口为系统接口,三方应用不支持调用 该接口为系统接口,三方应用不支持调用
- 属性
### 属性
| 名称 | 类型 | 说明 | | 名称 | 类型 | 说明 |
| --------- | ------ | -------------- | | --------- | ------ | -------------- |
......
# USB管理 # USB管理
本模块主要提供管理USB设备的相关功能,包括查询USB设备列表、批量数据传输、控制命令传输、权限控制等。
> **说明:** > **说明:**
>
> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块 ## 导入模块
......
# 卷管理 # 卷管理
该模块提供卷、磁盘查询和管理的相关功能:包括查询卷信息,对卷的挂载卸载、对磁盘分区以及卷的格式化等功能。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> >
> - 本模块首批接口从API version 9开始支持。 > - 本模块首批接口从API version 9开始支持。
> - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。 > - API 9当前为Canary版本,仅供试用,不保证接口可稳定调用。
> - 本模块接口为系统接口,三方应用不支持调用。 > - 本模块接口为系统接口,三方应用不支持调用。
该模块提供卷、磁盘查询和管理的相关功能:包括查询卷信息,对卷的挂载卸载、对磁盘分区以及卷的格式化等功能。
## 导入模块 ## 导入模块
```js ```js
...@@ -24,13 +24,13 @@ getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt; ...@@ -24,13 +24,13 @@ getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------------------- | -------------------------- | | ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)[]&gt; | 返回当前所有可获得的卷信息 | | Promise&lt;[Volume](#volume)[]&gt; | 返回当前所有可获得的卷信息 |
- 示例 **示例:**
```js ```js
volumemanager.getAllVolumes().then(function(volumes){ volumemanager.getAllVolumes().then(function(volumes){
...@@ -48,13 +48,13 @@ getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void ...@@ -48,13 +48,13 @@ getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------- | ---- | ------------------------------------ | | -------- | ------------------------------------------------- | ---- | ------------------------------------ |
| callback | callback:AsyncCallback&lt;[Volume](#volume)[]&gt; | 是 | 获取当前所有可获得的卷信息之后的回调 | | callback | callback:AsyncCallback&lt;[Volume](#volume)[]&gt; | 是 | 获取当前所有可获得的卷信息之后的回调 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
...@@ -74,19 +74,19 @@ mount(volumeId: string): Promise&lt;boolean&gt; ...@@ -74,19 +74,19 @@ mount(volumeId: string): Promise&lt;boolean&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| volumeId | string | 是 | 卷id | | volumeId | string | 是 | 卷id |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ---------- | | ---------------------- | ---------- |
| Promise&lt;boolean&gt; | 挂载指定卷 | | Promise&lt;boolean&gt; | 挂载指定卷 |
- 示例 **示例:**
```js ```js
let volumeId = ""; let volumeId = "";
...@@ -105,14 +105,14 @@ mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void ...@@ -105,14 +105,14 @@ mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | 是 | 卷id | | volumeId | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;boolean&gt; | 是 | 挂载指定卷之后的回调 | | callback | callback:AsyncCallback&lt;boolean&gt; | 是 | 挂载指定卷之后的回调 |
- 示例 **示例:**
```js ```js
let volumeId = ""; let volumeId = "";
...@@ -131,19 +131,19 @@ unmount(volumeId: string): Promise&lt;boolean&gt; ...@@ -131,19 +131,19 @@ unmount(volumeId: string): Promise&lt;boolean&gt;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| volumeId | string | 是 | 卷id | | volumeId | string | 是 | 卷id |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | ---------- | | ---------------------- | ---------- |
| Promise&lt;boolean&gt; | 卸载指定卷 | | Promise&lt;boolean&gt; | 卸载指定卷 |
- 示例 **示例:**
```js ```js
let volumeId = ""; let volumeId = "";
...@@ -162,14 +162,14 @@ unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void ...@@ -162,14 +162,14 @@ unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------- | ---- | -------------------- | | -------- | ------------------------------------- | ---- | -------------------- |
| volumeId | string | 是 | 卷id | | volumeId | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;boolean&gt; | 是 | 卸载指定卷之后的回调 | | callback | callback:AsyncCallback&lt;boolean&gt; | 是 | 卸载指定卷之后的回调 |
- 示例 **示例:**
```js ```js
let volumeId = ""; let volumeId = "";
...@@ -180,7 +180,7 @@ unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void ...@@ -180,7 +180,7 @@ unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
## volumemanager.getVolumeByUuid ## volumemanager.getVolumeByUuid
getVolumeByUuid(uuid: string): Promise<Volume>; getVolumeByUuid(uuid: string): Promise&lt;Volume&gt;
异步通过uuid获得卷信息,以promise方式返回。 异步通过uuid获得卷信息,以promise方式返回。
...@@ -188,19 +188,19 @@ getVolumeByUuid(uuid: string): Promise<Volume>; ...@@ -188,19 +188,19 @@ getVolumeByUuid(uuid: string): Promise<Volume>;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| uuid | string | 是 | 卷uuid | | uuid | string | 是 | 卷uuid |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------------------- | -------------------------- | | ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | 返回当前所有可获得的卷信息 | | Promise&lt;[Volume](#volume)&gt; | 返回当前所有可获得的卷信息 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
...@@ -209,7 +209,7 @@ getVolumeByUuid(uuid: string): Promise<Volume>; ...@@ -209,7 +209,7 @@ getVolumeByUuid(uuid: string): Promise<Volume>;
## volumemanager.getVolumeByUuid ## volumemanager.getVolumeByUuid
getVolumeByUuid(uuid: string, callback: AsyncCallback<Volume>): void; getVolumeByUuid(uuid: string, callback: AsyncCallback&lt;Volume&gt;): void
异步通过uuid获得卷信息,以callback方式返回。 异步通过uuid获得卷信息,以callback方式返回。
...@@ -217,14 +217,14 @@ getVolumeByUuid(uuid: string, callback: AsyncCallback<Volume>): void; ...@@ -217,14 +217,14 @@ getVolumeByUuid(uuid: string, callback: AsyncCallback<Volume>): void;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | -------------------- | | -------- | ------------------------------------------------ | ---- | -------------------- |
| uuid | string | 是 | 卷uuid | | uuid | string | 是 | 卷uuid |
| callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | 是 | 获取卷信息之后的回调 | | callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | 是 | 获取卷信息之后的回调 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
...@@ -235,7 +235,7 @@ getVolumeByUuid(uuid: string, callback: AsyncCallback<Volume>): void; ...@@ -235,7 +235,7 @@ getVolumeByUuid(uuid: string, callback: AsyncCallback<Volume>): void;
## volumemanager.getVolumeById ## volumemanager.getVolumeById
getVolumeById(id: string): Promise<Volume>; getVolumeById(id: string): Promise&lt;Volume&gt;
异步通过卷id获得卷信息,以promise方式返回。 异步通过卷id获得卷信息,以promise方式返回。
...@@ -243,19 +243,19 @@ getVolumeById(id: string): Promise<Volume>; ...@@ -243,19 +243,19 @@ getVolumeById(id: string): Promise<Volume>;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------ | ---- | ---- | | -------- | ------ | ---- | ---- |
| id | string | 是 | 卷id | | id | string | 是 | 卷id |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------------------- | -------------------------- | | ---------------------------------- | -------------------------- |
| Promise&lt;[Volume](#volume)&gt; | 返回当前所有可获得的卷信息 | | Promise&lt;[Volume](#volume)&gt; | 返回当前所有可获得的卷信息 |
- 示例 **示例:**
```js ```js
let id = ""; let id = "";
...@@ -264,7 +264,7 @@ getVolumeById(id: string): Promise<Volume>; ...@@ -264,7 +264,7 @@ getVolumeById(id: string): Promise<Volume>;
## volumemanager.getVolumeById ## volumemanager.getVolumeById
getVolumeById(id: string, callback: AsyncCallback<Volume>): void; getVolumeById(id: string, callback: AsyncCallback&lt;Volume&gt;): void
异步通过卷id获得卷信息,以callback方式返回。 异步通过卷id获得卷信息,以callback方式返回。
...@@ -272,14 +272,14 @@ getVolumeById(id: string, callback: AsyncCallback<Volume>): void; ...@@ -272,14 +272,14 @@ getVolumeById(id: string, callback: AsyncCallback<Volume>): void;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------------------------------ | ---- | -------------------- | | -------- | ------------------------------------------------ | ---- | -------------------- |
| id | string | 是 | 卷id | | id | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | 是 | 获取卷信息之后的回调 | | callback | callback:AsyncCallback&lt;[Volume](#volume)&gt; | 是 | 获取卷信息之后的回调 |
- 示例 **示例:**
```js ```js
let id = ""; let id = "";
...@@ -290,7 +290,7 @@ getVolumeById(id: string, callback: AsyncCallback<Volume>): void; ...@@ -290,7 +290,7 @@ getVolumeById(id: string, callback: AsyncCallback<Volume>): void;
## volumemanager.setVolumeDescription ## volumemanager.setVolumeDescription
setVolumeDescription(uuid: string, description: string): Promise<void>; setVolumeDescription(uuid: string, description: string): Promise&lt;void&gt;
异步通过uuid设置卷描述,以promise方式返回。 异步通过uuid设置卷描述,以promise方式返回。
...@@ -298,20 +298,20 @@ setVolumeDescription(uuid: string, description: string): Promise<void>; ...@@ -298,20 +298,20 @@ setVolumeDescription(uuid: string, description: string): Promise<void>;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| --------- | ------ | ---- | ---- | | --------- | ------ | ---- | ---- |
| uuid | string | 是 | 卷uuid | | uuid | string | 是 | 卷uuid |
| description | string | 是 | 卷描述 | | description | string | 是 | 卷描述 |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| ---------------------- | -------------------------- | | ---------------------- | -------------------------- |
| Promise&lt;void&gt; | 设置卷信息 | | Promise&lt;void&gt; | 设置卷信息 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
...@@ -321,7 +321,7 @@ setVolumeDescription(uuid: string, description: string): Promise<void>; ...@@ -321,7 +321,7 @@ setVolumeDescription(uuid: string, description: string): Promise<void>;
## volumemanager.setVolumeDescription ## volumemanager.setVolumeDescription
function setVolumeDescription(uuid: string, description: string, callback: AsyncCallback<void>): void; setVolumeDescription(uuid: string, description: string, callback: AsyncCallback&lt;void&gt;): void
异步通过uuid设置卷描述,以callback方式返回。 异步通过uuid设置卷描述,以callback方式返回。
...@@ -329,7 +329,7 @@ function setVolumeDescription(uuid: string, description: string, callback: Async ...@@ -329,7 +329,7 @@ function setVolumeDescription(uuid: string, description: string, callback: Async
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---------- | --------------------------------------- | ---- | ---------------- | | ---------- | --------------------------------------- | ---- | ---------------- |
...@@ -337,7 +337,7 @@ function setVolumeDescription(uuid: string, description: string, callback: Async ...@@ -337,7 +337,7 @@ function setVolumeDescription(uuid: string, description: string, callback: Async
| description | string | 是 | 卷描述 | | description | string | 是 | 卷描述 |
| callback | callback:AsyncCallback&lt;void&gt; | 是 | 设置卷描述之后的回调 | | callback | callback:AsyncCallback&lt;void&gt; | 是 | 设置卷描述之后的回调 |
- 示例 **示例:**
```js ```js
let uuid = ""; let uuid = "";
...@@ -349,7 +349,7 @@ function setVolumeDescription(uuid: string, description: string, callback: Async ...@@ -349,7 +349,7 @@ function setVolumeDescription(uuid: string, description: string, callback: Async
## volumemanager.format ## volumemanager.format
format(volId: string): Promise<void>; format(volId: string): Promise&lt;void&gt;
异步对指定卷进行格式化,以promise方式返回。 异步对指定卷进行格式化,以promise方式返回。
...@@ -357,19 +357,19 @@ format(volId: string): Promise<void>; ...@@ -357,19 +357,19 @@ format(volId: string): Promise<void>;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ---- | | ----------- | ------ | ---- | ---- |
| volId | string | 是 | 卷id | | volId | string | 是 | 卷id |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ----------------------- | | --------------------- | ----------------------- |
| Promise&lt;void&gt; | 对指定卷进行格式化 | | Promise&lt;void&gt; | 对指定卷进行格式化 |
- 示例 **示例:**
```js ```js
let volId = ""; let volId = "";
...@@ -378,7 +378,7 @@ format(volId: string): Promise<void>; ...@@ -378,7 +378,7 @@ format(volId: string): Promise<void>;
## volumemanager.format ## volumemanager.format
format(volId: string, callback: AsyncCallback<void>): void; format(volId: string, callback: AsyncCallback&lt;void&gt;): void
异步对指定卷进行格式化,以callback方式返回。 异步对指定卷进行格式化,以callback方式返回。
...@@ -386,14 +386,14 @@ format(volId: string, callback: AsyncCallback<void>): void; ...@@ -386,14 +386,14 @@ format(volId: string, callback: AsyncCallback<void>): void;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------- | | -------- | --------------------------------------- | ---- | ---------------- |
| volId | string | 是 | 卷id | | volId | string | 是 | 卷id |
| callback | callback:AsyncCallback&lt;void&gt; | 是 | 对指定卷进行格式化 | | callback | callback:AsyncCallback&lt;void&gt; | 是 | 对指定卷进行格式化 |
- 示例 **示例:**
```js ```js
let volId = ""; let volId = "";
...@@ -404,7 +404,7 @@ format(volId: string, callback: AsyncCallback<void>): void; ...@@ -404,7 +404,7 @@ format(volId: string, callback: AsyncCallback<void>): void;
## volumemanager.partition ## volumemanager.partition
partition(volId: string, fstype: string): Promise<void>; partition(volId: string, fstype: string): Promise&lt;void&gt;
异步对磁盘进行分区,以promise方式返回。 异步对磁盘进行分区,以promise方式返回。
...@@ -412,20 +412,20 @@ partition(volId: string, fstype: string): Promise<void>; ...@@ -412,20 +412,20 @@ partition(volId: string, fstype: string): Promise<void>;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
- 参数 **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ----------- | ------ | ---- | ---- | | ----------- | ------ | ---- | ---- |
| volId | string | 是 | 卷所属的磁盘id | | volId | string | 是 | 卷所属的磁盘id |
| fstype | string | 是 | 分区类型 | | fstype | string | 是 | 分区类型 |
- 返回值 **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| --------------------- | ----------------------- | | --------------------- | ----------------------- |
| Promise&lt;void&gt; | 对磁盘进行分区 | | Promise&lt;void&gt; | 对磁盘进行分区 |
- 示例 **示例:**
```js ```js
let volId = ""; let volId = "";
...@@ -435,7 +435,7 @@ partition(volId: string, fstype: string): Promise<void>; ...@@ -435,7 +435,7 @@ partition(volId: string, fstype: string): Promise<void>;
## volumemanager.partition ## volumemanager.partition
partition(volId: string, fstype : string, callback: AsyncCallback<void>): void; partition(volId: string, fstype : string, callback: AsyncCallback&lt;void&gt;): void
异步对磁盘进行分区,以callback方式返回。 异步对磁盘进行分区,以callback方式返回。
...@@ -443,9 +443,7 @@ partition(volId: string, fstype : string, callback: AsyncCallback<void>): void; ...@@ -443,9 +443,7 @@ partition(volId: string, fstype : string, callback: AsyncCallback<void>): void;
**系统能力**:SystemCapability.FileManagement.StorageService.Volume **系统能力**:SystemCapability.FileManagement.StorageService.Volume
**参数:**
- 参数
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------------- | | -------- | --------------------------------------- | ---- | ---------------- |
...@@ -453,7 +451,7 @@ partition(volId: string, fstype : string, callback: AsyncCallback<void>): void; ...@@ -453,7 +451,7 @@ partition(volId: string, fstype : string, callback: AsyncCallback<void>): void;
| fstype | string | 是 | 分区类型 | | fstype | string | 是 | 分区类型 |
| callback | callback:AsyncCallback&lt;void&gt; | 是 | 对磁盘进行分区 | | callback | callback:AsyncCallback&lt;void&gt; | 是 | 对磁盘进行分区 |
- 示例 **示例:**
```js ```js
let volId = ""; let volId = "";
......
# webgl # WebGL
WebGL提供图形绘制的能力,包括对当前绘制图形的位置、颜色等进行处理。
WebGL标准图形API,对应OpenGL ES 2.0特性集。更多信息请参考[WebGL™标准](https://www.khronos.org/registry/webgl/specs/latest/1.0/)
> **说明:** > **说明:**
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
WebGL标准图形API,对应OpenGL ES 2.0特性集。更多信息请参考[WebGL™标准](https://www.khronos.org/registry/webgl/specs/latest/1.0/)
## 调用方式 ## 调用方式
......
# webgl2 # WebGL2
WebGL2支持图形的绘制,包括对当前绘制图形的位置、颜色等进行处理,其中相对WebGL来说对渲染管道和着色语言进行了增强。
WebGL标准图形API,对应OpenGL ES 3.0特性集。更多信息请参考[WebGL™标准](https://www.khronos.org/registry/webgl/specs/latest/2.0/)
> **说明:** > **说明:**
>
> 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
WebGL标准图形API,对应OpenGL ES 3.0特性集。更多信息请参考[WebGL™标准](https://www.khronos.org/registry/webgl/specs/latest/2.0/)
## 调用方式 ## 调用方式
......
...@@ -33,10 +33,10 @@ Image(src: string | PixelMap | Resource) ...@@ -33,10 +33,10 @@ Image(src: string | PixelMap | Resource)
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| alt | string | - | 加载时显示的占位图。支持本地图片和网络路径。 | | alt | string | - | 加载时显示的占位图。支持本地图片和网络路径。 |
| objectFit | ImageFit | Cover | 设置图片的缩放类型。 | | objectFit | ImageFit | Cover | 设置图片的缩放类型。 |
| objectRepeat | [ImageRepeat](ts-appendix-enums.md#imagerepeat枚举说明) | NoRepeat | 设置图片的重复样式。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;SVG类型图源不支持该属性。 | | objectRepeat | [ImageRepeat](ts-appendix-enums.md#imagerepeat枚举说明) | NoRepeat | 设置图片的重复样式。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;svg类型图源不支持该属性。 |
| interpolation | ImageInterpolation | None | 设置图片的插值效果,仅针对图片放大插值。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;SVG类型图源不支持该属性。<br/>>&nbsp;<br/>>&nbsp;-&nbsp;PixelMap资源不支持该属性。 | | interpolation | ImageInterpolation | None | 设置图片的插值效果,仅针对图片放大插值。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;svg类型图源不支持该属性。<br/>>&nbsp;-&nbsp;PixelMap资源不支持该属性。 |
| renderMode | ImageRenderMode | Original | 设置图片渲染的模式。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;SVG类型图源不支持该属性。 | | renderMode | ImageRenderMode | Original | 设置图片渲染的模式。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;svg类型图源不支持该属性。 |
| sourceSize | {<br/>width:&nbsp;number,<br/>height:&nbsp;number<br/>} | - | 设置图片解码尺寸,将原始图片解码成指定尺寸的图片,number类型单位为px。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;PixelMap资源不支持该属性。 | | sourceSize | {<br/>width:&nbsp;number,<br/>height:&nbsp;number<br/>} | - | 设置图片解码尺寸,将原始图片解码成指定尺寸的图片,number类型单位为px。<br/>>&nbsp;![icon-note.gif](public_sys-resources/icon-note.gif)&nbsp;**说明:**<br/>>&nbsp;-&nbsp;PixelMap资源不支持该属性。 |
| syncLoad<sup>8+</sup> | boolean | false | 设置是否同步加载图片,默认是异步加载。同步加载时阻塞UI线程,不会显示占位图。 | | syncLoad<sup>8+</sup> | boolean | false | 设置是否同步加载图片,默认是异步加载。同步加载时阻塞UI线程,不会显示占位图。 |
- ImageFit枚举说明 - ImageFit枚举说明
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
## 接口 ## 接口
Refresh\(value: \{refreshing: boolean, offset?: Length, friction?: number\}\) Refresh\(value: \{refreshing: boolean, offset?: Length, friction?: number | string\}\)
- 参数 - 参数
...@@ -23,7 +23,7 @@ Refresh\(value: \{refreshing: boolean, offset?: Length, friction?: number\}\) ...@@ -23,7 +23,7 @@ Refresh\(value: \{refreshing: boolean, offset?: Length, friction?: number\}\)
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| refreshing | boolean | 是 | - | 当前组件是否正在刷新。 | | refreshing | boolean | 是 | - | 当前组件是否正在刷新。 |
| offset | Length | 否 | 16 | 刷新组件静止时距离父组件顶部的距离。| | offset | Length | 否 | 16 | 刷新组件静止时距离父组件顶部的距离。|
| friction | number | 否 | 62 | 下拉摩擦系数,取值范围为0到100。<br/>-&nbsp;0表示下拉刷新容器不跟随手势下拉而下拉。<br/>-&nbsp;100表示下拉刷新容器紧紧跟随手势下拉而下拉。<br/>-&nbsp;数值越大,下拉刷新容器跟随手势下拉的反应越灵敏。 | | friction | number&nbsp;\|&nbsp;string | 否 | 62 | 下拉摩擦系数,取值范围为0到100。<br/>-&nbsp;0表示下拉刷新容器不跟随手势下拉而下拉。<br/>-&nbsp;100表示下拉刷新容器紧紧跟随手势下拉而下拉。<br/>-&nbsp;数值越大,下拉刷新容器跟随手势下拉的反应越灵敏。 |
......
...@@ -165,7 +165,6 @@ struct VideoCreateComponent { ...@@ -165,7 +165,6 @@ struct VideoCreateComponent {
@State autoPlays: boolean = false; @State autoPlays: boolean = false;
@State controlsss: boolean = true; @State controlsss: boolean = true;
controller: VideoController = new VideoController(); controller: VideoController = new VideoController();
@State startStaus: boolean = true;
build() { build() {
Column() { Column() {
Video({ Video({
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
@Entry @Entry
@Component @Component
struct SharedTransitionExample { struct SharedTransitionExample {
@State scale: number = 1
@State opacity: number = 1
@State active: boolean = false @State active: boolean = false
build() { build() {
......
# Watchdog<a name="ZH-CN_TOPIC_0000001206372825"></a> # Watchdog
## 概述
## 概述<a name="section14918241977"></a>
看门狗(Watchdog),又叫看门狗计时器(Watchdog timer),是一种硬件的计时设备。当系统主程序发生错误导致未及时清除看门狗计时器的计时值时,看门狗计时器就会对系统发出复位信号,使系统从悬停状态恢复到正常运作状态。
看门狗(Watchdog),又叫看门狗计时器(Watchdog Timer),是一种硬件的计时设备,当系统的主程序发生某些错误时,导致未及时清除看门狗计时器的计时值,这时看门狗计时器就会对系统发出复位信号,使系统从悬停状态恢复到正常运作状态。
## 接口说明<a name="section1180575010271"></a> ## 接口说明
**表 1** 看门狗 API接口功能介绍 **表1** 看门狗API接口功能介绍
<a name="table1731550155318"></a> | 接口 | 接口描述 |
<table><thead align="left"><tr id="row4419501537"><th class="cellrowborder" valign="top" width="26.619999999999997%" id="mcps1.2.4.1.1"><p id="p641050105320"><a name="p641050105320"></a><a name="p641050105320"></a>功能分类</p> | -------- | -------- |
</th> | WatchdogOpen | 打开看门狗 |
<th class="cellrowborder" valign="top" width="32.800000000000004%" id="mcps1.2.4.1.2"><p id="p54150165315"><a name="p54150165315"></a><a name="p54150165315"></a>接口名</p> | WatchdogClose | 关闭看门狗 |
</th> | WatchdogStart | 启动看门狗 |
<th class="cellrowborder" valign="top" width="40.58%" id="mcps1.2.4.1.3"><p id="p941150145313"><a name="p941150145313"></a><a name="p941150145313"></a>描述</p> | WatchdogStop | 停止看门狗 |
</th> | WatchdogSetTimeout | 设置看门狗超时时间 |
</tr> | WatchdogGetTimeout | 获取看门狗超时时间 |
</thead> | WatchdogGetStatus | 获取看门狗状态 |
<tbody><tr id="row837081981712"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p681292481718"><a name="p681292481718"></a><a name="p681292481718"></a>打开/关闭看门狗</p> | WatchdogFeed | 清除看门狗定时器(喂狗) |
</td>
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p183701419141710"><a name="p183701419141710"></a><a name="p183701419141710"></a>WatchdogOpen</p> > ![](../public_sys-resources/icon-note.gif) **说明:**<br>
</td> > 本文涉及的看门狗的所有接口,仅限内核态使用,不支持在用户态使用。
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p17370161911710"><a name="p17370161911710"></a><a name="p17370161911710"></a>打开看门狗设备</p>
</td>
</tr> ## 使用指导
<tr id="row5610415171719"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p661171510173"><a name="p661171510173"></a><a name="p661171510173"></a>WatchdogClose</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p11611715161713"><a name="p11611715161713"></a><a name="p11611715161713"></a>关闭看门狗设备</p> ### 使用流程
</td>
</tr> 使用看门狗的一般流程如下图所示。
<tr id="row337105133315"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p07631557153319"><a name="p07631557153319"></a><a name="p07631557153319"></a>启动/停止看门狗</p>
</td> **图1** 看门狗使用流程图
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p163765113337"><a name="p163765113337"></a><a name="p163765113337"></a>WatchdogStart</p>
</td> ![image](figures/看门狗使用流程图.png "看门狗使用流程图")
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p18376517332"><a name="p18376517332"></a><a name="p18376517332"></a>启动看门狗</p>
</td>
</tr> ### 打开看门狗设备
<tr id="row18399184610337"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1740010461335"><a name="p1740010461335"></a><a name="p1740010461335"></a>WatchdogStop</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p19400194633318"><a name="p19400194633318"></a><a name="p19400194633318"></a>停止看门狗</p>
</td>
</tr>
<tr id="row34145016535"><td class="cellrowborder" rowspan="2" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p229610227124"><a name="p229610227124"></a><a name="p229610227124"></a>设置/获取超时时间</p>
</td>
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p8296182221219"><a name="p8296182221219"></a><a name="p8296182221219"></a>WatchdogSetTimeout</p>
</td>
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p16297172213125"><a name="p16297172213125"></a><a name="p16297172213125"></a>设置看门狗超时时间</p>
</td>
</tr>
<tr id="row11585016539"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1095722493616"><a name="p1095722493616"></a><a name="p1095722493616"></a>WatchdogGetTimeout</p>
</td>
<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p15297162215122"><a name="p15297162215122"></a><a name="p15297162215122"></a>获取看门狗超时时间</p>
</td>
</tr>
<tr id="row105701653185811"><td class="cellrowborder" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p2571145325819"><a name="p2571145325819"></a><a name="p2571145325819"></a>获取看门狗状态</p>
</td>
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p175711953195814"><a name="p175711953195814"></a><a name="p175711953195814"></a>WatchdogGetStatus</p>
</td>
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p331961319210"><a name="p331961319210"></a><a name="p331961319210"></a>获取看门狗状态</p>
</td>
</tr>
<tr id="row1028182217215"><td class="cellrowborder" valign="top" width="26.619999999999997%" headers="mcps1.2.4.1.1 "><p id="p182818227214"><a name="p182818227214"></a><a name="p182818227214"></a>清除看门狗定时器</p>
</td>
<td class="cellrowborder" valign="top" width="32.800000000000004%" headers="mcps1.2.4.1.2 "><p id="p17281223219"><a name="p17281223219"></a><a name="p17281223219"></a>WatchdogFeed</p>
</td>
<td class="cellrowborder" valign="top" width="40.58%" headers="mcps1.2.4.1.3 "><p id="p62815221125"><a name="p62815221125"></a><a name="p62815221125"></a>清除看门狗定时器(喂狗)</p>
</td>
</tr>
</tbody>
</table>
>![](../public_sys-resources/icon-note.gif) **说明:**
>本文涉及看门狗的所有接口,仅限内核态使用,不支持在用户态使用。
## 使用指导<a name="section10103184312813"></a>
### 使用流程<a name="section10181195910815"></a>
使用看门狗的一般流程如[图1](#fig430533913392)所示。
**图 1** 看门狗使用流程图<a name="fig430533913392"></a>
![](figures/看门狗使用流程图.png "看门狗使用流程图")
### 打开看门狗设备<a name="section66089201107"></a>
在操作看门狗之前,需要使用WatchdogOpen打开一个看门狗设备,一个系统可能有多个看门狗,通过ID号来打开指定的看门狗设备: 在操作看门狗之前,需要使用WatchdogOpen打开一个看门狗设备,一个系统可能有多个看门狗,通过ID号来打开指定的看门狗设备:
DevHandle WatchdogOpen\(int16\_t wdtId\); DevHandle WatchdogOpen(int16_t wdtId);
**表 2** WatchdogOpen参数和返回值描述 **表2** WatchdogOpen参数和返回值描述
<a name="table1413702552814"></a> | **参数** | **参数描述** |
<table><thead align="left"><tr id="row131371325142819"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p191372254283"><a name="p191372254283"></a><a name="p191372254283"></a><strong id="b1913716253285"><a name="b1913716253285"></a><a name="b1913716253285"></a>参数</strong></p> | -------- | -------- |
</th> | wdtId | 看门狗设备号 |
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p113819255284"><a name="p113819255284"></a><a name="p113819255284"></a><strong id="b151381725172812"><a name="b151381725172812"></a><a name="b151381725172812"></a>参数描述</strong></p> | **返回值** | **返回值描述** |
</th> | NULL | 打开失败 |
</tr> | DevHandle类型指针 | 看门狗设备句柄 |
</thead>
<tbody><tr id="row813812259282"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p101381625162813"><a name="p101381625162813"></a><a name="p101381625162813"></a>wdtId</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p191381425142813"><a name="p191381425142813"></a><a name="p191381425142813"></a>看门狗设备号</p>
</td>
</tr>
<tr id="row2138202515281"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p141387252287"><a name="p141387252287"></a><a name="p141387252287"></a><strong id="b11381325172810"><a name="b11381325172810"></a><a name="b11381325172810"></a>返回值</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p12138192512281"><a name="p12138192512281"></a><a name="p12138192512281"></a><strong id="b81380254286"><a name="b81380254286"></a><a name="b81380254286"></a>返回值描述</strong></p>
</td>
</tr>
<tr id="row9138182519287"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p5138102532814"><a name="p5138102532814"></a><a name="p5138102532814"></a>NULL</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p3138192512815"><a name="p3138192512815"></a><a name="p3138192512815"></a>打开失败</p>
</td>
</tr>
<tr id="row15138192518283"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1850115512916"><a name="p1850115512916"></a><a name="p1850115512916"></a>DevHandle类型指针</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p16138122512817"><a name="p16138122512817"></a><a name="p16138122512817"></a>看门狗设备句柄</p>
</td>
</tr>
</tbody>
</table>
``` ```
DevHandle handle = NULL; DevHandle handle = NULL;
...@@ -131,46 +62,21 @@ if (handle == NULL) { ...@@ -131,46 +62,21 @@ if (handle == NULL) {
} }
``` ```
### 获取看门狗状态<a name="section786624341011"></a>
### 获取看门狗状态
int32\_t WatchdogGetStatus\(DevHandle handle, int32\_t \*status\);
int32_t WatchdogGetStatus(DevHandle handle, int32_t *status);
**表 3** WatchdogGetStatus参数和返回值描述
**表3** WatchdogGetStatus参数和返回值描述
<a name="table1018490043"></a>
<table><thead align="left"><tr id="row31848013417"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1415816132411"><a name="p1415816132411"></a><a name="p1415816132411"></a><strong id="b129796117337"><a name="b129796117337"></a><a name="b129796117337"></a>参数</strong></p> | **参数** | **参数描述** |
</th> | -------- | -------- |
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p11158111316410"><a name="p11158111316410"></a><a name="p11158111316410"></a><strong id="b1699118123314"><a name="b1699118123314"></a><a name="b1699118123314"></a>参数描述</strong></p> | handle | 看门狗设备句柄 |
</th> | status | 获取到的看门狗状态的指针 |
</tr> | **返回值** | **返回值描述** |
</thead> | 0 | 获取成功 |
<tbody><tr id="row3264122711222"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p15264727182211"><a name="p15264727182211"></a><a name="p15264727182211"></a>handle</p> | 负数 | 获取失败 |
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p2026452772210"><a name="p2026452772210"></a><a name="p2026452772210"></a>看门狗设备句柄</p>
</td>
</tr>
<tr id="row928111518418"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p4282955412"><a name="p4282955412"></a><a name="p4282955412"></a>status</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p7282752412"><a name="p7282752412"></a><a name="p7282752412"></a>获取到的启动状态指针</p>
</td>
</tr>
<tr id="row17393154515328"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p8158313248"><a name="p8158313248"></a><a name="p8158313248"></a><strong id="b18542051332"><a name="b18542051332"></a><a name="b18542051332"></a>返回值</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p161591413741"><a name="p161591413741"></a><a name="p161591413741"></a><strong id="b45520523313"><a name="b45520523313"></a><a name="b45520523313"></a>返回值描述</strong></p>
</td>
</tr>
<tr id="row339324593215"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p103191916578"><a name="p103191916578"></a><a name="p103191916578"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p1231981611712"><a name="p1231981611712"></a><a name="p1231981611712"></a>获取成功</p>
</td>
</tr>
<tr id="row15393184519323"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p531916166716"><a name="p531916166716"></a><a name="p531916166716"></a>负数</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p93191161174"><a name="p93191161174"></a><a name="p93191161174"></a>获取失败</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -183,46 +89,21 @@ if (ret != 0) { ...@@ -183,46 +89,21 @@ if (ret != 0) {
} }
``` ```
### 设置超时时间<a name="section182386137111"></a>
### 设置超时时间
int32\_t WatchdogSetTimeout\(DevHandle \*handle, uint32\_t seconds\);
int32_t WatchdogSetTimeout(DevHandle *handle, uint32_t seconds);
**表 4** WatchdogSetTimeout参数和返回值描述
**表4** WatchdogSetTimeout参数和返回值描述
<a name="table9159112182210"></a>
<table><thead align="left"><tr id="row1216012212212"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1416017262215"><a name="p1416017262215"></a><a name="p1416017262215"></a><strong id="b181604212216"><a name="b181604212216"></a><a name="b181604212216"></a>参数</strong></p> | **参数** | **参数描述** |
</th> | -------- | -------- |
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p16160182192213"><a name="p16160182192213"></a><a name="p16160182192213"></a><strong id="b16160142162216"><a name="b16160142162216"></a><a name="b16160142162216"></a>参数描述</strong></p> | handle | 看门狗设备句柄 |
</th> | seconds | 超时时间,单位为秒 |
</tr> | **返回值** | **返回值描述** |
</thead> | 0 | 设置成功 |
<tbody><tr id="row199536232314"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p17685481236"><a name="p17685481236"></a><a name="p17685481236"></a>handle</p> | 负数 | 设置失败 |
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p196852811232"><a name="p196852811232"></a><a name="p196852811232"></a>看门狗设备句柄</p>
</td>
</tr>
<tr id="row141601729228"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p191601126226"><a name="p191601126226"></a><a name="p191601126226"></a>seconds</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p5160172182214"><a name="p5160172182214"></a><a name="p5160172182214"></a>超时时间,单位为秒</p>
</td>
</tr>
<tr id="row18160192172212"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p101601123222"><a name="p101601123222"></a><a name="p101601123222"></a><strong id="b516062172215"><a name="b516062172215"></a><a name="b516062172215"></a>返回值</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p17160192182212"><a name="p17160192182212"></a><a name="p17160192182212"></a><strong id="b141601022227"><a name="b141601022227"></a><a name="b141601022227"></a>返回值描述</strong></p>
</td>
</tr>
<tr id="row171600202220"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p121601226224"><a name="p121601226224"></a><a name="p121601226224"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p151607218222"><a name="p151607218222"></a><a name="p151607218222"></a>设置成功</p>
</td>
</tr>
<tr id="row916012252211"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p19160026224"><a name="p19160026224"></a><a name="p19160026224"></a>负数</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p816092142210"><a name="p816092142210"></a><a name="p816092142210"></a>设置失败</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -235,46 +116,21 @@ if (ret != 0) { ...@@ -235,46 +116,21 @@ if (ret != 0) {
} }
``` ```
### 获取超时时间<a name="section1883310371114"></a>
### 获取超时时间
int32\_t WatchdogGetTimeout\(DevHandle \*handle, uint32\_t \*seconds\);
int32_t WatchdogGetTimeout(DevHandle *handle, uint32_t *seconds);
**表 5** WatchdogGetTimeout参数和返回值描述
**表5** WatchdogGetTimeout参数和返回值描述
<a name="table10147164819233"></a>
<table><thead align="left"><tr id="row14147848142313"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p4147124892316"><a name="p4147124892316"></a><a name="p4147124892316"></a><strong id="b214784813238"><a name="b214784813238"></a><a name="b214784813238"></a>参数</strong></p> | **参数** | **参数描述** |
</th> | -------- | -------- |
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p12147144817232"><a name="p12147144817232"></a><a name="p12147144817232"></a><strong id="b51476482234"><a name="b51476482234"></a><a name="b51476482234"></a>参数描述</strong></p> | handle | 看门狗设备句柄 |
</th> | seconds | 接收超时时间的指针,单位为秒 |
</tr> | **返回值** | **返回值描述** |
</thead> | 0 | 获取成功 |
<tbody><tr id="row8147124819230"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p21471248142313"><a name="p21471248142313"></a><a name="p21471248142313"></a>handle</p> | 负数 | 获取失败 |
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p12147134815233"><a name="p12147134815233"></a><a name="p12147134815233"></a>看门狗设备句柄</p>
</td>
</tr>
<tr id="row514754818232"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1614713484235"><a name="p1614713484235"></a><a name="p1614713484235"></a>seconds</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p71478484238"><a name="p71478484238"></a><a name="p71478484238"></a>接收超时时间的指针,单位为秒</p>
</td>
</tr>
<tr id="row214784814239"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p5147848152314"><a name="p5147848152314"></a><a name="p5147848152314"></a><strong id="b17147124822310"><a name="b17147124822310"></a><a name="b17147124822310"></a>返回值</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p914724811236"><a name="p914724811236"></a><a name="p914724811236"></a><strong id="b614704813231"><a name="b614704813231"></a><a name="b614704813231"></a>返回值描述</strong></p>
</td>
</tr>
<tr id="row714744892312"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1014764832315"><a name="p1014764832315"></a><a name="p1014764832315"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p1314824872310"><a name="p1314824872310"></a><a name="p1314824872310"></a>获取成功</p>
</td>
</tr>
<tr id="row1514884815230"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p10148114822319"><a name="p10148114822319"></a><a name="p10148114822319"></a>负数</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p1314864822311"><a name="p1314864822311"></a><a name="p1314864822311"></a>获取失败</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -287,41 +143,20 @@ if (ret != 0) { ...@@ -287,41 +143,20 @@ if (ret != 0) {
} }
``` ```
### 启动看门狗<a name="section82501405123"></a>
### 启动看门狗
int32\_t WatchdogStart\(DevHandle handle\);
int32_t WatchdogStart(DevHandle handle);
**表 6** WatchdogStart参数和返回值描述
**表6** WatchdogStart参数和返回值描述
<a name="table529165182515"></a>
<table><thead align="left"><tr id="row92915122513"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p5292582517"><a name="p5292582517"></a><a name="p5292582517"></a><strong id="b12293510259"><a name="b12293510259"></a><a name="b12293510259"></a>参数</strong></p> | **参数** | **参数描述** |
</th> | -------- | -------- |
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p929554258"><a name="p929554258"></a><a name="p929554258"></a><strong id="b82913542514"><a name="b82913542514"></a><a name="b82913542514"></a>参数描述</strong></p> | handle | 看门狗设备句柄 |
</th> | **返回值** | **返回值描述** |
</tr> | 0 | 启动成功 |
</thead> | 负数 | 启动失败 |
<tbody><tr id="row629852250"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p22975122515"><a name="p22975122515"></a><a name="p22975122515"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p7290515256"><a name="p7290515256"></a><a name="p7290515256"></a>看门狗设备句柄</p>
</td>
</tr>
<tr id="row183035162514"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p8302511255"><a name="p8302511255"></a><a name="p8302511255"></a><strong id="b183018513251"><a name="b183018513251"></a><a name="b183018513251"></a>返回值</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p16307522515"><a name="p16307522515"></a><a name="p16307522515"></a><strong id="b23010542510"><a name="b23010542510"></a><a name="b23010542510"></a>返回值描述</strong></p>
</td>
</tr>
<tr id="row12305552510"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1730175132513"><a name="p1730175132513"></a><a name="p1730175132513"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p630754259"><a name="p630754259"></a><a name="p630754259"></a>启动成功</p>
</td>
</tr>
<tr id="row4306516252"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p15304502515"><a name="p15304502515"></a><a name="p15304502515"></a>负数</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p0301559254"><a name="p0301559254"></a><a name="p0301559254"></a>启动失败</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -333,41 +168,20 @@ if (ret != 0) { ...@@ -333,41 +168,20 @@ if (ret != 0) {
} }
``` ```
### 喂狗<a name="section3547530101211"></a>
### 喂狗
int32\_t WatchdogFeed\(DevHandle handle\);
int32_t WatchdogFeed(DevHandle handle);
**表 7** WatchdogFeed参数和返回值描述
**表7** WatchdogFeed参数和返回值描述
<a name="table091163515394"></a>
<table><thead align="left"><tr id="row891133515393"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p1911143513918"><a name="p1911143513918"></a><a name="p1911143513918"></a><strong id="b1791193553911"><a name="b1791193553911"></a><a name="b1791193553911"></a>参数</strong></p> | **参数** | **参数描述** |
</th> | -------- | -------- |
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p1191173553917"><a name="p1191173553917"></a><a name="p1191173553917"></a><strong id="b4911835183910"><a name="b4911835183910"></a><a name="b4911835183910"></a>参数描述</strong></p> | handle | 看门狗设备句柄 |
</th> | **返回值** | **返回值描述** |
</tr> | 0 | 喂狗成功 |
</thead> | 负数 | 喂狗失败 |
<tbody><tr id="row189111635143918"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p189111435173917"><a name="p189111435173917"></a><a name="p189111435173917"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p11911143511397"><a name="p11911143511397"></a><a name="p11911143511397"></a>看门狗设备句柄</p>
</td>
</tr>
<tr id="row15911835173916"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p7911123516396"><a name="p7911123516396"></a><a name="p7911123516396"></a><strong id="b59112352394"><a name="b59112352394"></a><a name="b59112352394"></a>返回值</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p169118356399"><a name="p169118356399"></a><a name="p169118356399"></a><strong id="b1091193593910"><a name="b1091193593910"></a><a name="b1091193593910"></a>返回值描述</strong></p>
</td>
</tr>
<tr id="row189119352393"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p1391113513917"><a name="p1391113513917"></a><a name="p1391113513917"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p149111435143911"><a name="p149111435143911"></a><a name="p149111435143911"></a>喂狗成功</p>
</td>
</tr>
<tr id="row5911123520392"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p49111335143920"><a name="p49111335143920"></a><a name="p49111335143920"></a>负数</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p1891216356391"><a name="p1891216356391"></a><a name="p1891216356391"></a>喂狗失败</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -379,41 +193,20 @@ if (ret != 0) { ...@@ -379,41 +193,20 @@ if (ret != 0) {
} }
``` ```
### 停止看门狗<a name="section944595841217"></a>
### 停止看门狗
int32\_t WatchdogStop\(DevHandle handle\);
int32_t WatchdogStop(DevHandle handle);
**表 8** WatchdogStop参数和返回值描述
**表8** WatchdogStop参数和返回值描述
<a name="table1286810515254"></a>
<table><thead align="left"><tr id="row28687517259"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p6868185120254"><a name="p6868185120254"></a><a name="p6868185120254"></a><strong id="b986815142510"><a name="b986815142510"></a><a name="b986815142510"></a>参数</strong></p> | **参数** | **参数描述** |
</th> | -------- | -------- |
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p15868185114252"><a name="p15868185114252"></a><a name="p15868185114252"></a><strong id="b148681451142517"><a name="b148681451142517"></a><a name="b148681451142517"></a>参数描述</strong></p> | handle | 看门狗设备句柄 |
</th> | **返回值** | **返回值描述** |
</tr> | 0 | 停止成功 |
</thead> | 负数 | 停止失败 |
<tbody><tr id="row1868165114256"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p6869105115256"><a name="p6869105115256"></a><a name="p6869105115256"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p19869951202513"><a name="p19869951202513"></a><a name="p19869951202513"></a>看门狗设备句柄</p>
</td>
</tr>
<tr id="row68696510259"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p2869165114256"><a name="p2869165114256"></a><a name="p2869165114256"></a><strong id="b386935117258"><a name="b386935117258"></a><a name="b386935117258"></a>返回值</strong></p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p158691551142517"><a name="p158691551142517"></a><a name="p158691551142517"></a><strong id="b78691751152513"><a name="b78691751152513"></a><a name="b78691751152513"></a>返回值描述</strong></p>
</td>
</tr>
<tr id="row9869851192516"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p686916516252"><a name="p686916516252"></a><a name="p686916516252"></a>0</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p7869115192510"><a name="p7869115192510"></a><a name="p7869115192510"></a>停止成功</p>
</td>
</tr>
<tr id="row15869951122519"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p486925112518"><a name="p486925112518"></a><a name="p486925112518"></a>负数</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p086945172518"><a name="p086945172518"></a><a name="p086945172518"></a>停止失败</p>
</td>
</tr>
</tbody>
</table>
``` ```
int32_t ret; int32_t ret;
...@@ -425,45 +218,38 @@ if (ret != 0) { ...@@ -425,45 +218,38 @@ if (ret != 0) {
} }
``` ```
### 关闭看门狗设备<a name="section96561824121311"></a>
### 关闭看门狗设备
当操作完毕时,使用WatchdogClose关闭打开的设备句柄: 当操作完毕时,使用WatchdogClose关闭打开的设备句柄:
void WatchdogClose\(DevHandle handle\); void WatchdogClose(DevHandle handle);
**表 9** WatchdogClose参数和返回值描述 **表9** WatchdogClose参数和返回值描述
<a name="table1017315185320"></a> | **参数** | **参数描述** |
<table><thead align="left"><tr id="row417314182327"><th class="cellrowborder" valign="top" width="44.99%" id="mcps1.2.3.1.1"><p id="p117310184320"><a name="p117310184320"></a><a name="p117310184320"></a><strong id="b141734185327"><a name="b141734185327"></a><a name="b141734185327"></a>参数</strong></p> | -------- | -------- |
</th> | handle | 看门狗设备句柄 |
<th class="cellrowborder" valign="top" width="55.010000000000005%" id="mcps1.2.3.1.2"><p id="p7173191812324"><a name="p7173191812324"></a><a name="p7173191812324"></a><strong id="b2017318188327"><a name="b2017318188327"></a><a name="b2017318188327"></a>参数描述</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="row1617331823211"><td class="cellrowborder" valign="top" width="44.99%" headers="mcps1.2.3.1.1 "><p id="p17173191811326"><a name="p17173191811326"></a><a name="p17173191811326"></a>handle</p>
</td>
<td class="cellrowborder" valign="top" width="55.010000000000005%" headers="mcps1.2.3.1.2 "><p id="p538814308323"><a name="p538814308323"></a><a name="p538814308323"></a>看门狗设备句柄</p>
</td>
</tr>
</tbody>
</table>
``` ```
/* 关闭看门狗 */ /* 关闭看门狗 */
ret = WatchdogClose(handle); ret = WatchdogClose(handle);
``` ```
## 使用实例<a name="section1724514523135"></a>
## 使用实例
本例程提供看门狗的完整使用流程。 本例程提供看门狗的完整使用流程。
在本例程中,我们打开一个看门狗设备,设置超时时间并启动计时: 在本例程中,我们打开一个看门狗设备,设置超时时间并启动计时:
- 首先定期喂狗,即按时清除看门狗定时器,确保系统不会因定时器超时而复位。 - 首先定期喂狗,即按时清除看门狗定时器,确保系统不会因定时器超时而复位。
- 接着再停止喂狗,观察定时器到期后系统是否发生复位行为。
示例如下: - 接着再停止喂狗,观察定时器到期后系统是否发生复位行为。
示例如下:
``` ```
#include "watchdog_if.h" #include "watchdog_if.h"
#include "hdf_log.h" #include "hdf_log.h"
...@@ -483,7 +269,7 @@ static int32_t TestCaseWatchdog(void) ...@@ -483,7 +269,7 @@ static int32_t TestCaseWatchdog(void)
/* 打开0号看门狗设备 */ /* 打开0号看门狗设备 */
handle = WatchdogOpen(0); handle = WatchdogOpen(0);
if (handle == NULL) { if (handle == NULL) {
HDF_LOGE("Open watchdog fail!"); HDF_LOGE("Open watchdog failed!");
return -1; return -1;
} }
...@@ -507,14 +293,14 @@ static int32_t TestCaseWatchdog(void) ...@@ -507,14 +293,14 @@ static int32_t TestCaseWatchdog(void)
/* 启动看门狗,开始计时 */ /* 启动看门狗,开始计时 */
ret = WatchdogStart(handle); ret = WatchdogStart(handle);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: satrt fail! ret:%d\n", __func__, ret); HDF_LOGE("%s: start fail! ret:%d\n", __func__, ret);
WatchdogClose(handle); WatchdogClose(handle);
return ret; return ret;
} }
/* 每隔1S喂狗一次 */ /* 每隔1S喂狗一次 */
for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) { for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) {
HDF_LOGE("%s: feeding watchdog %d times... \n", __func__, i); HDF_LOGI("%s: feeding watchdog %d times... \n", __func__, i);
ret = WatchdogFeed(handle); ret = WatchdogFeed(handle);
if (ret != HDF_SUCCESS) { if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: feed dog fail! ret:%d\n", __func__, ret); HDF_LOGE("%s: feed dog fail! ret:%d\n", __func__, ret);
...@@ -524,18 +310,17 @@ static int32_t TestCaseWatchdog(void) ...@@ -524,18 +310,17 @@ static int32_t TestCaseWatchdog(void)
OsalSleep(1); OsalSleep(1);
} }
/* 由于喂狗间隔小于超时时间,系统不会发生复位,此日志可以正常打印 */ /* 由于喂狗间隔小于超时时间,系统不会发生复位,此日志可以正常打印 */
HDF_LOGE("%s: no reset ... feeding test OK!!!\n", __func__); HDF_LOGI("%s: no reset ... feeding test OK!!!\n", __func__);
/* 接下来持续不喂狗,使得看门狗计时器超时 */ /* 接下来持续不喂狗,使得看门狗计时器超时 */
for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) { for (i = 0; i < WATCHDOG_TEST_FEED_TIME; i++) {
HDF_LOGE("%s: watiting dog back %d times... \n", __func__, i); HDF_LOGI("%s: waiting dog buck %d times... \n", __func__, i);
OsalSleep(1); OsalSleep(1);
} }
/* 当不喂狗时间到达之前设定的超时时间的时候,系统会发生复位,理论上观察不到此日志的打印 */ /* 当不喂狗时间到达之前设定的超时时间的时候,系统会发生复位,理论上观察不到此日志的打印 */
HDF_LOGE("%s: dog hasn't back!!! \n", __func__, i); HDF_LOGI("%s: dog hasn't back!!! \n", __func__, i);
WatchdogClose(handle); WatchdogClose(handle);
return -1; return -1;
} }
``` ```
\ No newline at end of file
# WatchDog<a name="ZH-CN_TOPIC_0000001176922470"></a> # Watchdog
## 概述<a name="section1315827527160117"></a> ## 概述
看门狗(Watchdog),又叫看门狗计时器(Watchdog timer),是一种硬件的计时设备在HDF框架中,Watchdog接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。 看门狗(Watchdog),又叫看门狗计时器(Watchdog timer),是一种硬件的计时设备在HDF框架中,Watchdog接口适配模式采用独立服务模式,在这种模式下,每一个设备对象会独立发布一个设备服务来处理外部访问,设备管理器收到API的访问请求之后,通过提取该请求的参数,达到调用实际设备对象的相应内部方法的目的。独立服务模式可以直接借助HDFDeviceManager的服务管理能力,但需要为每个设备单独配置设备节点,增加内存占用。
**图 1** Watchdog独立服务模式结构图<a name="fig61584136211"></a> **图1** Watchdog独立服务模式结构图
![](figures/独立服务模式结构图.png "Watchdog独立服务模式结构图")
## 接口说明<a name="section752964871810"></a> ![image](figures/独立服务模式结构图.png "Watchdog独立服务模式结构图")
## 接口说明
WatchdogMethod定义: WatchdogMethod定义:
``` ```
struct WatchdogMethod { struct WatchdogMethod {
int32_t (*getStatus)(struct WatchdogCntlr *wdt, int32_t *status); int32_t (*getStatus)(struct WatchdogCntlr *wdt, int32_t *status);
...@@ -20,342 +23,238 @@ struct WatchdogMethod { ...@@ -20,342 +23,238 @@ struct WatchdogMethod {
int32_t (*start)(struct WatchdogCntlr *wdt); int32_t (*start)(struct WatchdogCntlr *wdt);
int32_t (*stop)(struct WatchdogCntlr *wdt); int32_t (*stop)(struct WatchdogCntlr *wdt);
int32_t (*feed)(struct WatchdogCntlr *wdt); int32_t (*feed)(struct WatchdogCntlr *wdt);
int32_t (*getPriv)(struct WatchdogCntlr *wdt); //【可选】如果WatchdogCntlr 中的priv成员存在,则按需实例化 int32_t (*getPriv)(struct WatchdogCntlr *wdt); // 【可选】如果WatchdogCntlr中的priv成员存在,则按需实例化
void (*releasePriv)(struct WatchdogCntlr *wdt);//【可选】 void (*releasePriv)(struct WatchdogCntlr *wdt);// 【可选】
}; };
``` ```
**表 1** WatchdogMethod成员的回调函数功能说明 **表1** WatchdogMethod成员的回调函数功能说明
<a name="table1370451732"></a> | 成员函数 | 入参 | 出参 | 返回值 | 功能 |
<table><thead align="left"><tr id="row370511435"><th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.1"><p id="p170681939"><a name="p170681939"></a><a name="p170681939"></a>成员函数</p> | -------- | -------- | -------- | -------- | -------- |
</th> | getStatus | wdt:结构体指针,核心层WDG控制器 | status:&nbsp;int32_t指针,表示狗的状态(打开或关闭) | HDF_STATUS相关状态 | 获取看门狗所处的状态 |
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.2"><p id="p870641434"><a name="p870641434"></a><a name="p870641434"></a>入参</p> | start | wdt:结构体指针,核心层WDG控制器 | 无 | HDF_STATUS相关状态 | 打开开门狗 |
</th> | stop | wdt:结构体指针,核心层WDG控制器 | 无 | HDF_STATUS相关状态 | 关闭开门狗 |
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.3"><p id="p27061011739"><a name="p27061011739"></a><a name="p27061011739"></a>出参</p> | setTimeout | wdt:结构体指针,核心层WDG控制器 | seconds:&nbsp;uint32_t,时间传入值; | 无 | HDF_STATUS相关状态 | 设置超时时间值,单位秒,需要保证看门狗实际运行的时间符合该值 |
</th> | getTimeout | wdt:结构体指针,核心层WDG控制器 | seconds:&nbsp;uint32_t,传出的时间值 | HDF_STATUS相关状态 | 回读设置的超时时间值 |
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.4"><p id="p10707618315"><a name="p10707618315"></a><a name="p10707618315"></a>返回值</p> | feed | wdt:结构体指针,核心层WDG控制器 | 无 | HDF_STATUS相关状态 | 喂狗 |
</th>
<th class="cellrowborder" valign="top" width="20%" id="mcps1.2.6.1.5"><p id="p37071516316"><a name="p37071516316"></a><a name="p37071516316"></a>功能</p>
</th> ## 开发步骤
</tr>
</thead>
<tbody><tr id="row18707191835"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p970720118311"><a name="p970720118311"></a><a name="p970720118311"></a>getStatus</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p124968261413"><a name="p124968261413"></a><a name="p124968261413"></a>wdt: 结构体指针,核心层WDG控制器;</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p17071515316"><a name="p17071515316"></a><a name="p17071515316"></a>status: int32_t指针,表示狗的状态(打开或关闭);</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p5707319312"><a name="p5707319312"></a><a name="p5707319312"></a>HDF_STATUS相关状态</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p2707511312"><a name="p2707511312"></a><a name="p2707511312"></a>获取看门狗所处的状态</p>
</td>
</tr>
<tr id="row27071911538"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p370701533"><a name="p370701533"></a><a name="p370701533"></a>start</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p117071316317"><a name="p117071316317"></a><a name="p117071316317"></a>wdt: 结构体指针,核心层WDG控制器;</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p127071411735"><a name="p127071411735"></a><a name="p127071411735"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p19707111331"><a name="p19707111331"></a><a name="p19707111331"></a>HDF_STATUS相关状态</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p170811111319"><a name="p170811111319"></a><a name="p170811111319"></a>打开开门狗</p>
</td>
</tr>
<tr id="row17708191130"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p11708113315"><a name="p11708113315"></a><a name="p11708113315"></a>stop</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p870841138"><a name="p870841138"></a><a name="p870841138"></a>wdt: 结构体指针,核心层WDG控制器;</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p770841533"><a name="p770841533"></a><a name="p770841533"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p18708115313"><a name="p18708115313"></a><a name="p18708115313"></a>HDF_STATUS相关状态</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p3708121738"><a name="p3708121738"></a><a name="p3708121738"></a>关闭开门狗</p>
</td>
</tr>
<tr id="row107081818310"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p10708181136"><a name="p10708181136"></a><a name="p10708181136"></a>setTimeout</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p1870801834"><a name="p1870801834"></a><a name="p1870801834"></a>wdt: 结构体指针,核心层WDG控制器;seconds: uint32_t,时间传入值;</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p77081011731"><a name="p77081011731"></a><a name="p77081011731"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p470871436"><a name="p470871436"></a><a name="p470871436"></a>HDF_STATUS相关状态</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p57091717315"><a name="p57091717315"></a><a name="p57091717315"></a>设置超时时间值,单位秒,需要保证看门狗实际运行的时间符合该值</p>
</td>
</tr>
<tr id="row3709911938"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p2070911932"><a name="p2070911932"></a><a name="p2070911932"></a>getTimeout</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p47091711732"><a name="p47091711732"></a><a name="p47091711732"></a>wdt: 结构体指针,核心层WDG控制器;</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p57091411632"><a name="p57091411632"></a><a name="p57091411632"></a>seconds: uint32_t,传出的时间值</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p1470941838"><a name="p1470941838"></a><a name="p1470941838"></a>HDF_STATUS相关状态</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p17091511139"><a name="p17091511139"></a><a name="p17091511139"></a>回读设置的超时时间值</p>
</td>
</tr>
<tr id="row1770919112319"><td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.1 "><p id="p1270913116313"><a name="p1270913116313"></a><a name="p1270913116313"></a>feed</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.2 "><p id="p570971736"><a name="p570971736"></a><a name="p570971736"></a>wdt: 结构体指针,核心层WDG控制器;</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.3 "><p id="p67091517315"><a name="p67091517315"></a><a name="p67091517315"></a></p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.4 "><p id="p1670915111312"><a name="p1670915111312"></a><a name="p1670915111312"></a>HDF_STATUS相关状态</p>
</td>
<td class="cellrowborder" valign="top" width="20%" headers="mcps1.2.6.1.5 "><p id="p10709818316"><a name="p10709818316"></a><a name="p10709818316"></a>喂狗</p>
</td>
</tr>
</tbody>
</table>
## 开发步骤<a name="section477974542160117"></a>
Watchdog模块适配HDF框架的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。 Watchdog模块适配HDF框架的三个环节是配置属性文件,实例化驱动入口,以及实例化核心层接口函数。
1. **实例化驱动入口:** 1. **实例化驱动入口:**
- 实例化HdfDriverEntry结构体成员。 - 实例化HdfDriverEntry结构体成员。
- 调用HDF\_INIT将HdfDriverEntry实例化对象注册到HDF框架中。 - 调用HDF_INIT将HdfDriverEntry实例化对象注册到HDF框架中。
2. **配置属性文件:** 2. **配置属性文件:**
- 在device\_info.hcs文件中添加deviceNode描述。 - 在device_info.hcs文件中添加deviceNode描述。
- 【可选】添加watchdog\_config.hcs器件属性文件。 - 【可选】添加watchdog_config.hcs器件属性文件。
3. **实例化Watchdog控制器对象:** 3. **实例化Watchdog控制器对象:**
- 初始化WatchdogCntlr成员。 - 初始化WatchdogCntlr成员。
- 实例化WatchdogCntlr成员WatchdogMethod。 - 实例化WatchdogCntlr成员WatchdogMethod。
> ![](../public_sys-resources/icon-note.gif) **说明:**<br>
>![](../public_sys-resources/icon-note.gif) **说明:** > 实例化WatchdogCntlr成员WatchdogMethod,其定义和成员说明见[接口说明](#接口说明)。
>实例化WatchdogCntlr成员WatchdogMethod,其定义和成员说明见[接口说明](#section752964871810)。
4. **驱动调试:**
【可选】针对新增驱动程序,建议验证驱动基本功能,例如挂载后的信息反馈,超时时间设置的成功与否等。
4. **驱动调试:**
【可选】针对新增驱动程序,建议验证驱动基本功能,例如挂载后的信息反馈,超时时间设置的成功与否等。 ## 开发实例
下方将以watchdog_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。
## 开发实例<a name="section1832270347160117"></a>
1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf_device_desc.h 中定义)类型的全局变量,且moduleName要和device_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。
下方将以watchdog\_hi35xx.c为示例,展示需要厂商提供哪些内容来完整实现设备功能。 一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。
1. 驱动开发首先需要实例化驱动入口,驱动入口必须为HdfDriverEntry(在 hdf\_device\_desc.h 中定义)类型的全局变量,且moduleName要和device\_info.hcs中保持一致。HDF框架会将所有加载的驱动的HdfDriverEntry对象首地址汇总,形成一个类似数组的段地址空间,方便上层调用。 Watchdog驱动入口参考:
一般在加载驱动时HDF会先调用Bind函数,再调用Init函数加载该驱动。当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 ```
struct HdfDriverEntry g_watchdogDriverEntry = {
Watchdog驱动入口参考: .moduleVersion = 1,
.Bind = Hi35xxWatchdogBind, // 见Bind参考
``` .Init = Hi35xxWatchdogInit, // 见Init参考
struct HdfDriverEntry g_watchdogDriverEntry = { .Release = Hi35xxWatchdogRelease, // 见Release参考
.moduleVersion = 1, .moduleName = "HDF_PLATFORM_WATCHDOG",// 【必要且与HCS文件中里面的moduleName匹配】
.Bind = Hi35xxWatchdogBind, //见Bind参考 };
.Init = Hi35xxWatchdogInit, //见Init参考 HDF_INIT(g_watchdogDriverEntry);// 调用HDF_INIT将驱动入口注册到HDF框架中
.Release = Hi35xxWatchdogRelease, //见Release参考 ```
.moduleName = "HDF_PLATFORM_WATCHDOG",//【必要且与HCS文件中里面的moduleName匹配】
}; 2. 完成驱动入口注册之后,下一步请在device_info.hcs文件中添加deviceNode信息,并在 watchdog_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层WatchdogCntlr 成员的默认值或限制范围有密切关系。
HDF_INIT(g_watchdogDriverEntry);//调用HDF_INIT将驱动入口注册到HDF框架中 本例只有一个Watchdog控制器,如有多个器件信息,则需要在device_info文件增加deviceNode信息,以及在watchdog_config文件中增加对应的器件属性。
``` - device_info.hcs 配置参考:
2. 完成驱动入口注册之后,下一步请在device\_info.hcs文件中添加deviceNode信息,并在 watchdog\_config.hcs 中配置器件属性。deviceNode信息与驱动入口注册相关,器件属性值与核心层WatchdogCntlr 成员的默认值或限制范围有密切关系。
```
本例只有一个Watchdog控制器,如有多个器件信息,则需要在device\_info文件增加deviceNode信息,以及在watchdog\_config文件中增加对应的器件属性。 root {
device_info {
- device\_info.hcs 配置参考。 match_attr = "hdf_manager";
device_watchdog :: device { // 设备节点
``` device0 :: deviceNode { // 驱动的DeviceNode节点
root { policy = 1; // policy字段是驱动服务发布的策略,如果需要面向用户态,则为2
device_info { priority = 20; // 驱动启动优先级
match_attr = "hdf_manager"; permission = 0644; // 驱动创建设备节点权限
device_watchdog :: device { // 设备节点 moduleName = "HDF_PLATFORM_WATCHDOG";
device0 :: deviceNode { // 驱动的DeviceNode节点 // 【必要】驱动名称,该字段的值必须和驱动入口结构的moduleName值一致
policy = 1; // policy字段是驱动服务发布的策略,如果需要面向用户态,则为2 serviceName = "HDF_PLATFORM_WATCHDOG_0";
priority = 20; // 驱动启动优先级 // 【必要且唯一】驱动对外发布服务的名称
permission = 0644; // 驱动创建设备节点权限 deviceMatchAttr = "hisilicon_hi35xx_watchdog_0";
moduleName = "HDF_PLATFORM_WATCHDOG"; // 【必要】驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的match_attr值相等
// 【必要】驱动名称,该字段的值必须和驱动入口结构的moduleName值一致 }
serviceName = "HDF_PLATFORM_WATCHDOG_0"; }
// 【必要且唯一】驱动对外发布服务的名称 }
deviceMatchAttr = "hisilicon_hi35xx_watchdog_0"; }
// 【必要】驱动私有数据匹配的关键字,必须和驱动私有数据配置表中的match_attr值相等 ```
}
} - watchdog_config.hcs 配置参考:
}
}
``` ```
root {
- watchdog\_config.hcs 配置参考。 platform {
template watchdog_controller {// 【必要】模板配置,继承该模板的节点如果使用模板中的默认值,则节点字段可以缺省
``` id = 0;
root { match_attr = "";
platform { regBase = 0x12050000; // 【必要】地址映射需要
template watchdog_controller {//【必要】模板配置,继承该模板的节点如果使用模板中的默认值,则节点字段可以缺省 regStep = 0x1000; // 【必要】地址映射需要
id = 0; }
match_attr = ""; controller_0x12050000 :: watchdog_controller {// 【必要】是作为设备驱动私有数据匹配的关键字
regBase = 0x12050000; //【必要】地址映射需要 match_attr = "hisilicon_hi35xx_watchdog_0"; // 【必要】必须和device_info.hcs中的deviceMatchAttr值一致
regStep = 0x1000; //【必要】地址映射需要 }
} // 存在多个 watchdog 时【必须】添加,否则不用
controller_0x12050000 :: watchdog_controller {//【必要】是作为设备驱动私有数据匹配的关键字 ...
match_attr = "hisilicon_hi35xx_watchdog_0"; //【必要】必须和device_info.hcs中的deviceMatchAttr值一致 }
} }
//存在多个 watchdog 时【必须】添加,否则不用 ```
...
} 3. 完成驱动入口注册之后,最后一步就是以核心层WatchdogCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化WatchdogCntlr成员WatchdogMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。
} - 自定义结构体参考。
```
从驱动的角度看,自定义结构体是参数和数据的载体,而且watchdog_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,其中一些重要数值也会传递给核心层WatchdogCntlr对象,例如索引、管脚数等。
3. 完成驱动入口注册之后,最后一步就是以核心层WatchdogCntlr对象的初始化为核心,包括厂商自定义结构体(传递参数和数据),实例化WatchdogCntlr成员WatchdogMethod(让用户可以通过接口来调用驱动底层函数),实现HdfDriverEntry成员函数(Bind,Init,Release)。
- 自定义结构体参考。
```
从驱动的角度看,自定义结构体是参数和数据的载体,而且watchdog\_config.hcs文件中的数值会被HDF读入通过DeviceResourceIface来初始化结构体成员,其中一些重要数值也会传递给核心层WatchdogCntlr对象,例如索引、管脚数等。 struct Hi35xxWatchdog {
struct WatchdogCntlr wdt; // 【必要】是链接上下层的载体,具体描述见下面
``` OsalSpinlock lock;
struct Hi35xxWatchdog { volatile unsigned char *regBase;// 【必要】地址映射需要
struct WatchdogCntlr wdt; //【必要】是链接上下层的载体,具体描述见下面 uint32_t phyBase; // 【必要】地址映射需要
OsalSpinlock lock; uint32_t regStep; // 【必要】地址映射需要
volatile unsigned char *regBase;//【必要】地址映射需要 };
uint32_t phyBase; //【必要】地址映射需要 // WatchdogCntlr是核心层控制器结构体,其中的成员在Init函数中会被赋值
uint32_t regStep; //【必要】地址映射需要 struct WatchdogCntlr {
}; struct IDeviceIoService service;// 驱动服务
//WatchdogCntlr是核心层控制器结构体,其中的成员在Init函数中会被赋值 struct HdfDeviceObject *device; // 驱动设备
struct WatchdogCntlr { OsalSpinlock lock; // 此变量在HDF核心层被调用来实现自旋锁功能
struct IDeviceIoService service;//驱动服务 struct WatchdogMethod *ops; // 接口回调函数
struct HdfDeviceObject *device; //驱动设备 int16_t wdtId; // WDG设备的识别id
OsalSpinlock lock; //此变量在HDF核心层被调用来实现自旋锁功能 void *priv; // 存储指针
struct WatchdogMethod *ops; //接口回调函数 };
int16_t wdtId; //WDG设备的识别id ```
void *priv; //存储指针 - WatchdogCntlr成员回调函数结构体WatchdogMethod的实例化,其他成员在Init和Bind函数中初始化。
};
```
- WatchdogCntlr成员回调函数结构体WatchdogMethod的实例化,其他成员在Init和Bind函数中初始化。
```
static struct WatchdogMethod g_method = {
.getStatus = Hi35xxWatchdogGetStatus,
.start = Hi35xxWatchdogStart,
.stop = Hi35xxWatchdogStop,
.setTimeout = Hi35xxWatchdogSetTimeout,
.getTimeout = Hi35xxWatchdogGetTimeout,
.feed = Hi35xxWatchdogFeed,
};
```
- Init函数和Bind函数参考
入参:
HdfDeviceObject :HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口。
返回值:
HDF\_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见//drivers/framework/include/utils/hdf\_base.h中HDF\_STATUS 定义)。
**表 2** Init函数和Bind函数入参和返回值
<a name="table86931033998"></a>
<table><thead align="left"><tr id="row10694203319911"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1669433319918"><a name="p1669433319918"></a><a name="p1669433319918"></a>状态(值)</p>
</th>
<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p06945331911"><a name="p06945331911"></a><a name="p06945331911"></a>问题描述</p>
</th>
</tr>
</thead>
<tbody><tr id="row869417338918"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p96941433391"><a name="p96941433391"></a><a name="p96941433391"></a>HDF_ERR_INVALID_OBJECT</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p4694333395"><a name="p4694333395"></a><a name="p4694333395"></a>找不到 WDG 设备</p>
</td>
</tr>
<tr id="row136941833091"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p66941336920"><a name="p66941336920"></a><a name="p66941336920"></a>HDF_ERR_MALLOC_FAIL</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1694133395"><a name="p1694133395"></a><a name="p1694133395"></a>内存分配失败</p>
</td>
</tr>
<tr id="row469443317913"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p116951933293"><a name="p116951933293"></a><a name="p116951933293"></a>HDF_ERR_IO</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p969511331918"><a name="p969511331918"></a><a name="p969511331918"></a>I/O 错误</p>
</td>
</tr>
<tr id="row369533318911"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p669511331891"><a name="p669511331891"></a><a name="p669511331891"></a>HDF_SUCCESS</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p136951233699"><a name="p136951233699"></a><a name="p136951233699"></a>初始化成功</p>
</td>
</tr>
<tr id="row17695633596"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1469583314910"><a name="p1469583314910"></a><a name="p1469583314910"></a>HDF_FAILURE</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p10695193311919"><a name="p10695193311919"></a><a name="p10695193311919"></a>初始化失败</p>
</td>
</tr>
</tbody>
</table>
函数说明:
初始化自定义结构体对象,初始化WatchdogCntlr成员,调用核心层WatchdogCntlrAdd函数。
```
//一般而言,Init函数需要根据入参(HdfDeviceObject对象)的属性值初始化Hi35xxWatchdog结构体的成员,
//但本例中是在bind函数中实现的
static int32_t Hi35xxWatchdogInit(struct HdfDeviceObject *device)
{
(void)device;
return HDF_SUCCESS;
}
static int32_t Hi35xxWatchdogBind(struct HdfDeviceObject *device) ```
{ static struct WatchdogMethod g_method = {
int32_t ret; .getStatus = Hi35xxWatchdogGetStatus,
struct Hi35xxWatchdog *hwdt = NULL; .start = Hi35xxWatchdogStart,
... .stop = Hi35xxWatchdogStop,
hwdt = (struct Hi35xxWatchdog *)OsalMemCalloc(sizeof(*hwdt));//Hi35xxWatchdog 结构体的内存申请 .setTimeout = Hi35xxWatchdogSetTimeout,
... .getTimeout = Hi35xxWatchdogGetTimeout,
hwdt->regBase = OsalIoRemap(hwdt->phyBase, hwdt->regStep); //地址映射 .feed = Hi35xxWatchdogFeed,
... };
hwdt->wdt.priv = (void *)device->property;//【可选】此处是将设备属性的内容赋值给priv成员,但后续没有调用 priv 成员, ```
// 如果需要用到priv成员,需要额外实例化WatchdogMethod的getPriv和releasePriv成员函数
hwdt->wdt.ops = &g_method; //【必要】将实例化后的对象赋值给ops成员,就可以实现顶层调用WatchdogMethod成员函数 - Init函数和Bind函数参考:
hwdt->wdt.device = device; //【必要】这是为了方便HdfDeviceObject与WatchdogcCntlr相互转化
ret = WatchdogCntlrAdd(&hwdt->wdt); //【必要】调用此函数初始化核心层结构体,返回成功信号后驱动才完全接入平台核心层
if (ret != HDF_SUCCESS) { //不成功的话,需要释放Init函数申请的资源
OsalIoUnmap((void *)hwdt->regBase);
OsalMemFree(hwdt);
return ret;
}
return HDF_SUCCESS;
}
```
- Release函数参考
入参:
HdfDeviceObject :HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口。
返回值:
无。
函数说明:
该函数需要在驱动入口结构体中赋值给Release,当HDF框架调用Init函数初始化驱动失败时,可以调用Release释放驱动资源。该函数中需包含释放内存和删除控制器等操作。所有强制转换获取相应对象的操作前提是在Init函数中具备对应赋值的操作。
```
static void Hi35xxWatchdogRelease(struct HdfDeviceObject *device)
{
struct WatchdogCntlr *wdt = NULL;
struct Hi35xxWatchdog *hwdt = NULL;
...
wdt = WatchdogCntlrFromDevice(device);//这里会通过service成员将HdfDeviceObject转化为WatchdogCntlr
//return (device == NULL) ? NULL : (struct WatchdogCntlr *)device->service;
if (wdt == NULL) {
return;
}
WatchdogCntlrRemove(wdt); //核心层函数,实际执行wdt->device->service = NULL以及cntlr->lock的释放
hwdt = (struct Hi35xxWatchdog *)wdt; //这里将WatchdogCntlr转化为HimciHost
if (hwdt->regBase != NULL) { //解除地址映射
OsalIoUnmap((void *)hwdt->regBase);
hwdt->regBase = NULL;
}
OsalMemFree(hwdt); //释放厂商自定义对象占用的内存
}
```
入参:
HdfDeviceObject :HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口。
返回值:
HDF_STATUS相关状态 (下表为部分展示,如需使用其他状态,可见// drivers/framework/include/utils/hdf_base.h中HDF_STATUS 定义)。
**表2** Init函数和Bind函数入参和返回值
| 状态(值) | 问题描述 |
| -------- | -------- |
| HDF_ERR_INVALID_OBJECT | 找不到&nbsp;WDG&nbsp;设备 |
| HDF_ERR_MALLOC_FAIL | 内存分配失败 |
| HDF_ERR_IO | I/O&nbsp;错误 |
| HDF_SUCCESS | 初始化成功 |
| HDF_FAILURE | 初始化失败 |
函数说明:
初始化自定义结构体对象,初始化WatchdogCntlr成员,调用核心层WatchdogCntlrAdd函数。
```
// 一般而言,Init函数需要根据入参(HdfDeviceObject对象)的属性值初始化Hi35xxWatchdog结构体的成员,
// 但本例中是在bind函数中实现的
static int32_t Hi35xxWatchdogInit(struct HdfDeviceObject *device)
{
(void)device;
return HDF_SUCCESS;
}
static int32_t Hi35xxWatchdogBind(struct HdfDeviceObject *device)
{
int32_t ret;
struct Hi35xxWatchdog *hwdt = NULL;
...
hwdt = (struct Hi35xxWatchdog *)OsalMemCalloc(sizeof(*hwdt));// Hi35xxWatchdog 结构体的内存申请
...
hwdt->regBase = OsalIoRemap(hwdt->phyBase, hwdt->regStep); // 地址映射
...
hwdt->wdt.priv = (void *)device->property;// 【可选】此处是将设备属性的内容赋值给priv成员,但后续没有调用 priv 成员,
// 如果需要用到priv成员,需要额外实例化WatchdogMethod的getPriv和releasePriv成员函数
hwdt->wdt.ops = &g_method; // 【必要】将实例化后的对象赋值给ops成员,就可以实现顶层调用WatchdogMethod成员函数
hwdt->wdt.device = device; // 【必要】这是为了方便HdfDeviceObject与WatchdogcCntlr相互转化
ret = WatchdogCntlrAdd(&hwdt->wdt); // 【必要】调用此函数初始化核心层结构体,返回成功信号后驱动才完全接入平台核心层
if (ret != HDF_SUCCESS) { // 不成功的话,需要释放Init函数申请的资源
OsalIoUnmap((void *)hwdt->regBase);
OsalMemFree(hwdt);
return ret;
}
return HDF_SUCCESS;
}
```
- Release函数参考:
入参:
HdfDeviceObject:HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口。
返回值:
无。
函数说明:
该函数需要在驱动入口结构体中赋值给Release,当HDF框架调用Init函数初始化驱动失败时,可以调用Release释放驱动资源。该函数中需包含释放内存和删除控制器等操作。所有强制转换获取相应对象的操作前提是在Init函数中具备对应赋值的操作。
```
static void Hi35xxWatchdogRelease(struct HdfDeviceObject *device)
{
struct WatchdogCntlr *wdt = NULL;
struct Hi35xxWatchdog *hwdt = NULL;
...
wdt = WatchdogCntlrFromDevice(device);// 这里会通过service成员将HdfDeviceObject转化为WatchdogCntlr
// return (device == NULL) ? NULL : (struct WatchdogCntlr *)device->service;
if (wdt == NULL) {
return;
}
WatchdogCntlrRemove(wdt); // 核心层函数,实际执行wdt->device->service = NULL以及cntlr->lock的释放
hwdt = (struct Hi35xxWatchdog *)wdt; // 这里将WatchdogCntlr转化为HimciHost
if (hwdt->regBase != NULL) { // 解除地址映射
OsalIoUnmap((void *)hwdt->regBase);
hwdt->regBase = NULL;
}
OsalMemFree(hwdt); // 释放厂商自定义对象占用的内存
}
```
\ No newline at end of file
# HiCollie开发指导<a name="ZH-CN_TOPIC_0000001231255509"></a> # HiCollie开发指导<a name="ZH-CN_TOPIC_0000001231255509"></a>
- [概述](#section3432134085116)
- [接口说明](#section139261151145116)
- [效果](#section1589120102458)
- [开发实例](#section13905646534)
- [C++接口开发实例](#section9797199145316)
- [线程卡死监控](#section1734221332)
- [超时监控](#section2186947140)
## 概述<a name="section3432134085116"></a> ## 概述<a name="section3432134085116"></a>
......
# HiLog\_Lite开发指导<a name="ZH-CN_TOPIC_0000001185815838"></a> # HiLog\_Lite开发指导<a name="ZH-CN_TOPIC_0000001185815838"></a>
- [概述](#section775017517390)
- [接口说明](#section114412157402)
- [开发实例](#section1482812550419)
## 概述<a name="section775017517390"></a> ## 概述<a name="section775017517390"></a>
......
# HiSysEvent订阅指导<a name="ZH-CN_TOPIC_0000001185655868"></a> # HiSysEvent订阅指导<a name="ZH-CN_TOPIC_0000001185655868"></a>
- [概述](#section315316685112)
- [功能简介](#section123181433335224)
- [约束与限制](#section123181433375224)
- [开发指导](#section315316685113)
- [接口说明](#section0342191810519)
- [开发实例](#section123181432175110)
## 概述<a name="section315316685112"></a> ## 概述<a name="section315316685112"></a>
......
# HiSysEvent查询指导<a name="ZH-CN_TOPIC_0000001231455461"></a> # HiSysEvent查询指导<a name="ZH-CN_TOPIC_0000001231455461"></a>
- [概述](#section279684125212)
- [开发指导](#section315316761113)
- [接口说明](#section03869128521)
- [开发实例](#section14286111855212)
## 概述<a name="section279684125212"></a> ## 概述<a name="section279684125212"></a>
......
# HiSysEvent工具使用指导<a name="ZH-CN_TOPIC_0000001231614021"></a> # HiSysEvent工具使用指导<a name="ZH-CN_TOPIC_0000001231614021"></a>
- [概述](#section1886702718521)
- [实时订阅HiSysEvent事件相关命令](#section1210623418527)
- [查询历史HiSysEvent事件相关命令](#section1210623418539)
## 概述<a name="section1886702718521"></a> ## 概述<a name="section1886702718521"></a>
......
# HiTrace开发指导<a name="ZH-CN_TOPIC_0000001186134310"></a> # HiTrace开发指导<a name="ZH-CN_TOPIC_0000001186134310"></a>
- [概述](#section3986195420436)
- [应用场景](#section134561822574)
- [业务使用示例](#section63861653124417)
- [接口说明](#section1517945334617)
- [接口形式对比](#section932504474)
- [接口功能参数](#section2514638125)
- [通信调用处理](#section11257133933)
- [开发实例](#section14310412491)
- [C++接口实例](#section114916381509)
- [C接口实例](#section108292107514)
## 概述<a name="section3986195420436"></a> ## 概述<a name="section3986195420436"></a>
......
# DFX概述<a name="ZH-CN_TOPIC_0000001185974398"></a> # DFX概述<a name="ZH-CN_TOPIC_0000001185974398"></a>
- [基本概念](#section5635178134811)
在OpenHarmony中,DFX\([Design for X](https://en.wikipedia.org/wiki/Design_for_X)\)是为了提升质量属性的软件设计,目前包含的内容主要有:DFR(Design for Reliability,可靠性)和DFT(Design for Testability,可测试性)特性。 在OpenHarmony中,DFX\([Design for X](https://en.wikipedia.org/wiki/Design_for_X)\)是为了提升质量属性的软件设计,目前包含的内容主要有:DFR(Design for Reliability,可靠性)和DFT(Design for Testability,可测试性)特性。
......
# 动画开发指导<a name="ZH-CN_TOPIC_0000001051451654"></a> # 动画开发指导<a name="ZH-CN_TOPIC_0000001051451654"></a>
- [使用场景](#section726685714018)
- [接口说明](#section85794718418)
- [开发步骤](#section14101161317435)
## 使用场景<a name="section726685714018"></a> ## 使用场景<a name="section726685714018"></a>
UI动画通过task处理机制每个tick调用一下用户设置的callback函数来实现,具体实现为AnimatorManager、Animator、AnimatorCallback三个类实现。 UI动画通过task处理机制每个tick调用一下用户设置的callback函数来实现,具体实现为AnimatorManager、Animator、AnimatorCallback三个类实现。
......
# 普通组件开发指导<a name="ZH-CN_TOPIC_0000001052170409"></a> # 普通组件开发指导<a name="ZH-CN_TOPIC_0000001052170409"></a>
- [UIButton](#section145353310214)
- [使用场景](#section1169616141577)
- [接口说明](#section341211538315)
- [开发步骤](#section22501726193214)
- [UIImageView](#section19523161611259)
- [使用场景](#section1274484210400)
- [接口说明](#section74981992411)
- [开发步骤(自适应)](#section144341333134114)
- [开发步骤(平铺模式)](#section97178160421)
- [UILabel](#section16588132012911)
- [使用场景](#section6870195634218)
- [接口说明](#section2012714510433)
- [开发步骤(默认模式)](#section83221538114410)
- [开发步骤(背景色和透明度)](#section933360204510)
- [开发步骤(字符间距)](#section19447826124518)
- [开发步骤(大小自适应)](#section101711842154617)
- [开发步骤(省略号模式)](#section1249519410471)
- [开发步骤(滚动模式)](#section15643122618478)
普通组件均继承于基类UIView,不可以添加子组件,常用的普通组件有button、image、label等。 普通组件均继承于基类UIView,不可以添加子组件,常用的普通组件有button、image、label等。
......
# 容器类组件开发指导<a name="ZH-CN_TOPIC_0000001052810390"></a> # 容器类组件开发指导<a name="ZH-CN_TOPIC_0000001052810390"></a>
- [UIViewGroup](#section145471898812)
- [使用场景](#section0916112362216)
- [接口说明](#section12641756192212)
- [开发步骤](#section5412161692311)
- [UIScrollView](#section174961523161315)
- [使用场景](#section8937101902413)
- [接口说明](#section14789133142420)
- [开发步骤](#section1769754422417)
容器类组件,指能包含其它UI组件的组件,容器类组件继承于UIViewGroup(带Add方法),基于实际组件的使用场景,将需要增加其他子组件的组件,放置到容器类继承结构下。如UIAnalogClock内,通常会Add需要的计步信息,时分秒图标等。 容器类组件,指能包含其它UI组件的组件,容器类组件继承于UIViewGroup(带Add方法),基于实际组件的使用场景,将需要增加其他子组件的组件,放置到容器类继承结构下。如UIAnalogClock内,通常会Add需要的计步信息,时分秒图标等。
......
# 布局容器类组件开发指导<a name="ZH-CN_TOPIC_0000001052661991"></a> # 布局容器类组件开发指导<a name="ZH-CN_TOPIC_0000001052661991"></a>
- [UISwipeView](#section13631719181717)
- [使用场景](#section11299120102617)
- [接口说明](#section767434119261)
- [开发步骤(水平滑动,不可循环)](#section111911175287)
- [开发步骤(水平滑动,可循环)](#section1976914915282)
- [GridLayout](#section46819199173)
- [使用场景](#section831618247294)
- [接口说明](#section597214622912)
- [开发步骤](#section1418253410306)
布局类容器组件由视图基础类组成,通过直接设置视图位置,可以达到嵌套和重叠布局的目的;通过设置布局类型和边距达到规格化布局子组件的目的;通过调用相关接口可实现根据父组件及兄弟节点布局视图的目的。 布局类容器组件由视图基础类组成,通过直接设置视图位置,可以达到嵌套和重叠布局的目的;通过设置布局类型和边距达到规格化布局子组件的目的;通过调用相关接口可实现根据父组件及兄弟节点布局视图的目的。
......
# 图形图像概述<a name="ZH-CN_TOPIC_0000001051770388"></a> # 图形图像概述<a name="ZH-CN_TOPIC_0000001051770388"></a>
- [UI组件](#section1987017145112)
- [布局](#section662016231612)
- [动画](#section73736284117)
- [Input事件](#section672194012114)
- [渲染](#section14338859916)
OpenHarmony图形系统,提供基础UI组件和容器类组件,包括button、image、label、list、animator、scroll view、swipe view、font、clock、chart、canvas、slider、layout等。同时提供截屏、导出组件树的DFX能力。模块内部实现组件渲染、动画、输入事件分发等功能。 OpenHarmony图形系统,提供基础UI组件和容器类组件,包括button、image、label、list、animator、scroll view、swipe view、font、clock、chart、canvas、slider、layout等。同时提供截屏、导出组件树的DFX能力。模块内部实现组件渲染、动画、输入事件分发等功能。
......
# 相机开发概述<a name="ZH-CN_TOPIC_0000001051690589"></a> # 相机开发概述<a name="ZH-CN_TOPIC_0000001051690589"></a>
- [基本概念](#section175012297491)
- [运作机制](#section193961322175011)
## 基本概念<a name="section175012297491"></a> ## 基本概念<a name="section175012297491"></a>
相机是OpenHarmony多媒体进程提供的服务之一,提供了相机的录像、预览、拍照功能,支持多用户并发取流。 相机是OpenHarmony多媒体进程提供的服务之一,提供了相机的录像、预览、拍照功能,支持多用户并发取流。
......
# 拍照开发指导<a name="ZH-CN_TOPIC_0000001052170554"></a> # 拍照开发指导<a name="ZH-CN_TOPIC_0000001052170554"></a>
- [使用场景](#section1963312376119)
- [接口说明](#section56549532016)
- [约束与限制](#section1165911177314)
- [开发步骤](#section138543918214)
## 使用场景<a name="section1963312376119"></a> ## 使用场景<a name="section1963312376119"></a>
......
# 预览开发指导<a name="ZH-CN_TOPIC_0000001051930577"></a> # 预览开发指导<a name="ZH-CN_TOPIC_0000001051930577"></a>
- [使用场景](#section186634310418)
- [接口说明](#section125479541744)
- [约束与限制](#section1165911177314)
- [开发步骤](#section34171333656)
## 使用场景<a name="section186634310418"></a> ## 使用场景<a name="section186634310418"></a>
......
# 录像开发指导<a name="ZH-CN_TOPIC_0000001051451869"></a> # 录像开发指导<a name="ZH-CN_TOPIC_0000001051451869"></a>
- [使用场景](#section186634310418)
- [接口说明](#section125479541744)
- [约束与限制](#section1165911177314)
- [开发步骤](#section1196016315516)
## 使用场景<a name="section186634310418"></a> ## 使用场景<a name="section186634310418"></a>
......
# 音视频开发概述<a name="ZH-CN_TOPIC_0000001051770578"></a> # 音视频开发概述<a name="ZH-CN_TOPIC_0000001051770578"></a>
- [基本概念](#section967213571204)
- [编解码规格](#section1582020483111)
OpenHarmony音视频包括音视频播放和录制。 OpenHarmony音视频包括音视频播放和录制。
......
# 音视频播放开发指导<a name="ZH-CN_TOPIC_0000001051930589"></a> # 音视频播放开发指导<a name="ZH-CN_TOPIC_0000001051930589"></a>
- [使用场景](#section186634310418)
- [接口说明](#section125479541744)
- [约束与限制](#section1165911177314)
- [开发步骤](#section34171333656)
## 使用场景<a name="section186634310418"></a> ## 使用场景<a name="section186634310418"></a>
......
# 音视频录制开发指导<a name="ZH-CN_TOPIC_0000001052170566"></a> # 音视频录制开发指导<a name="ZH-CN_TOPIC_0000001052170566"></a>
- [使用场景](#section186634310418)
- [接口说明](#section125479541744)
- [约束与限制](#section1165911177314)
- [开发步骤](#section34171333656)
## 使用场景<a name="section186634310418"></a> ## 使用场景<a name="section186634310418"></a>
音视频录制的主要功能是录制音视频,并根据设置的编码格式、采样率、码率等参数封装输出文件。 音视频录制的主要功能是录制音视频,并根据设置的编码格式、采样率、码率等参数封装输出文件。
......
# 分布式远程启动<a name="ZH-CN_TOPIC_0000001051071561"></a> # 分布式远程启动<a name="ZH-CN_TOPIC_0000001051071561"></a>
- [概述](#section186634310418)
- [基本概念](#section982651246)
- [接口说明](#section125479541744)
- [约束与限制](#section1165911177314)
- [开发步骤](#section34171333656)
## 概述<a name="section186634310418"></a> ## 概述<a name="section186634310418"></a>
分布式任务调度模块,通过主从设备服务代理机制,在OpenHarmony操作系统上建立起分布式服务平台,支持主设备\(搭载OpenHarmony的智慧屏设备\)启动从设备\(IP Camera、运动手表等小内存OpenHarmony设备\)FA的能力。 分布式任务调度模块,通过主从设备服务代理机制,在OpenHarmony操作系统上建立起分布式服务平台,支持主设备\(搭载OpenHarmony的智慧屏设备\)启动从设备\(IP Camera、运动手表等小内存OpenHarmony设备\)FA的能力。
......
# IPC通信鉴权开发指导<a name="ZH-CN_TOPIC_0000001058671861"></a> # IPC通信鉴权开发指导<a name="ZH-CN_TOPIC_0000001058671861"></a>
- [场景介绍](#section18502174174019)
- [接口说明](#section1633115419401)
- [开发步骤](#section022611498210)
- [常见问题](#section15729104510271)
## 场景介绍<a name="section18502174174019"></a> ## 场景介绍<a name="section18502174174019"></a>
......
# 应用权限管理开发指导<a name="ZH-CN_TOPIC_0000001058864249"></a> # 应用权限管理开发指导<a name="ZH-CN_TOPIC_0000001058864249"></a>
- [运作机制](#section193961322175011)
- [场景介绍](#section18502174174019)
- [接口说明](#section1633115419401)
- [开发步骤](#section022611498210)
## 运作机制<a name="section193961322175011"></a> ## 运作机制<a name="section193961322175011"></a>
由于OpenHarmony允许安装三方应用,所以需要对三方应用的敏感权限调用进行管控,具体实现是应用在开发阶段就需要在profile.json中指明此应用在运行过程中可能会调用哪些敏感权限,这些权限包括静态权限和动态权限,静态权限表示只需要在安装阶段注册就可以,而动态权限一般表示获取用户的敏感信息,所以需要在运行时让用户确认才可以调用,授权方式包括系统设置应用手动授权等。除了运行时对应用调用敏感权限进行管控外,还需要利用应用签名管控手段确保应用安装包已经被设备厂商进行了确认。 由于OpenHarmony允许安装三方应用,所以需要对三方应用的敏感权限调用进行管控,具体实现是应用在开发阶段就需要在profile.json中指明此应用在运行过程中可能会调用哪些敏感权限,这些权限包括静态权限和动态权限,静态权限表示只需要在安装阶段注册就可以,而动态权限一般表示获取用户的敏感信息,所以需要在运行时让用户确认才可以调用,授权方式包括系统设置应用手动授权等。除了运行时对应用调用敏感权限进行管控外,还需要利用应用签名管控手段确保应用安装包已经被设备厂商进行了确认。
......
# 应用验签开发指导<a name="ZH-CN_TOPIC_0000001058671627"></a> # 应用验签开发指导<a name="ZH-CN_TOPIC_0000001058671627"></a>
- [场景介绍](#section18502174174019)
- [验签流程](#section554632717226)
- [接口说明](#section1633115419401)
- [开发步骤](#section4207112818418)
- [生成OpenHarmony签名应用](#section167151429133312)
## 场景介绍<a name="section18502174174019"></a> ## 场景介绍<a name="section18502174174019"></a>
......
# 电话服务开发指导<a name="ZH-CN_TOPIC_0000001167051994"></a> # 电话服务开发指导<a name="ZH-CN_TOPIC_0000001167051994"></a>
- [Modem厂商库初始化开发指导](#section211mcpsimp)
- [场景介绍](#section213mcpsimp)
- [接口说明](#section811343241215)
- [开发步骤](#section51031144122)
- [调测验证](#section5351151517132)
- [Modem业务请求及响应开发指导](#section295mcpsimp)
- [场景介绍](#section297mcpsimp)
- [接口说明](#section9503155219134)
- [开发步骤](#section17190412101414)
- [调测验证](#section10207938171413)
- [Modem事件上报开发指导](#section390mcpsimp)
- [场景介绍](#section401mcpsimp)
- [接口说明](#section191193791518)
- [开发步骤](#section16394112401512)
- [调测验证](#section16999174401516)
- [开发实例](#section33444350167)
- [Modem厂商库集成指导](#section590mcpsimp)
- [编译设置](#section592mcpsimp)
- [调测验证](#section620mcpsimp)
## Modem厂商库初始化开发指导<a name="section211mcpsimp"></a> ## Modem厂商库初始化开发指导<a name="section211mcpsimp"></a>
......
# 电话服务概述<a name="ZH-CN_TOPIC_0000001164469232"></a> # 电话服务概述<a name="ZH-CN_TOPIC_0000001164469232"></a>
- [概述](#section184mcpsimp)
- [基本概念](#section187mcpsimp)
- [运作机制](#section194mcpsimp)
- [约束与限制](#section205mcpsimp)
## 概述<a name="section184mcpsimp"></a> ## 概述<a name="section184mcpsimp"></a>
本指南简要介绍了Modem厂商库的集成、初始化、业务请求响应和事件上报的方法,并通过通话业务的具体开发实例呈现厂商库的适配开发过程,供不同Modem芯片的开发者参考,从而帮助其高效地实现电话相关业务功能的开发。 本指南简要介绍了Modem厂商库的集成、初始化、业务请求响应和事件上报的方法,并通过通话业务的具体开发实例呈现厂商库的适配开发过程,供不同Modem芯片的开发者参考,从而帮助其高效地实现电话相关业务功能的开发。
......
# USB服务子系统使用指导<a name="ZH-CN_TOPIC_0000001077367159"></a> # USB服务子系统使用指导<a name="ZH-CN_TOPIC_0000001077367159"></a>
- [使用步骤](#section18816105182315)
下面使用步骤以bulktransfer为例。 下面使用步骤以bulktransfer为例。
......
# USB服务子系统概述<a name="ZH-CN_TOPIC_0000001092893508"></a> # USB服务子系统概述<a name="ZH-CN_TOPIC_0000001092893508"></a>
- [概述](#section175431838101617)
- [接口说明](#section83365421647)
- [Host部分](#section83365421658)
- [Device部分](#section83365421669)
- [Port部分](#section83365421670)
## 概述<a name="section175431838101617"></a> ## 概述<a name="section175431838101617"></a>
......
...@@ -32,12 +32,13 @@ ...@@ -32,12 +32,13 @@
**表1** 版本软件和工具配套关系 **表1** 版本软件和工具配套关系
| 软件 | 版本 | 备注 | | 软件 | 版本 | 备注 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| OpenHarmony | 3.1.1&nbsp;Release | NA | | OpenHarmony | 3.1.1&nbsp;Release | NA |
| SDK | Ohos_sdk_full&nbsp;3.1.6.5 (API&nbsp;Version&nbsp;8&nbsp;Release) | NA | | Public SDK | Ohos_sdk_public&nbsp;3.1.6.6 (API&nbsp;Version&nbsp;8&nbsp;Release) | 面向应用开发者提供,不包含需要使用系统权限的系统接口。<br/>DevEco Studio 3.0 Beta4版本起,通过DevEco Studio获取的SDK默认为Public SDK。<br/>该版本Public SDK于7月6日单独更新发布。 |
| HUAWEI&nbsp;DevEco&nbsp;Studio(可选) | 3.0&nbsp;Beta3&nbsp;for&nbsp;OpenHarmony | OpenHarmony应用开发推荐使用 | | Full SDK | Ohos_sdk_full&nbsp;3.1.6.5 (API&nbsp;Version&nbsp;8&nbsp;Release) | 面向OEM厂商提供,包含了需要使用系统权限的系统接口。<br/>使用Full SDK时需要手动从镜像站点获取,并在DevEco Studio中替换,具体操作可参考[替换指南](../application-dev/quick-start/full-sdk-switch-guide.md)。 |
| HUAWEI&nbsp;DevEco&nbsp;Device&nbsp;Tool(可选) | 3.0&nbsp;Release | OpenHarmony智能设备集成开发环境推荐使用 | | HUAWEI&nbsp;DevEco&nbsp;Studio(可选) | 3.0&nbsp;Beta3&nbsp;for&nbsp;OpenHarmony | OpenHarmony应用开发推荐使用。 |
| HUAWEI&nbsp;DevEco&nbsp;Device&nbsp;Tool(可选) | 3.0&nbsp;Release | OpenHarmony智能设备集成开发环境推荐使用。 |
## 源码获取 ## 源码获取
...@@ -101,8 +102,10 @@ repo forall -c 'git lfs pull' ...@@ -101,8 +102,10 @@ repo forall -c 'git lfs pull'
| Hi3861轻量系统解决方案(二进制) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_pegasus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_pegasus.tar.gz.sha256) | | Hi3861轻量系统解决方案(二进制) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_pegasus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_pegasus.tar.gz.sha256) |
| Hi3516轻量系统解决方案-LiteOS(二进制) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_taurus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_taurus.tar.gz.sha256) | | Hi3516轻量系统解决方案-LiteOS(二进制) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_taurus.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_taurus.tar.gz.sha256) |
| Hi3516轻量系统解决方案-Linux(二进制) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_taurus_linux.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_taurus_linux.tar.gz.sha256) | | Hi3516轻量系统解决方案-Linux(二进制) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_taurus_linux.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/hispark_taurus_linux.tar.gz.sha256) |
| 标准系统SDK包(Mac) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-mac-full.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-mac-full.tar.gz.sha256) | | 标准系统Full SDK包(Mac) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-mac-full.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-mac-full.tar.gz.sha256) |
| 标准系统SDK包(Windows\Linux) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-full.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-full.tar.gz.sha256) | | 标准系统Full SDK包(Windows\Linux) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-full.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-full.tar.gz.sha256) |
| 标准系统Public SDK包(Mac) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-mac-public.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-mac-public.tar.gz.sha256) |
| 标准系统Public SDK包(Windows\Linux) | 3.1.1 Release | [站点](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-public.tar.gz) | [SHA256校验码](https://repo.huaweicloud.com/openharmony/os/3.1.1/ohos-sdk-public.tar.gz.sha256) |
## 更新说明 ## 更新说明
...@@ -114,21 +117,22 @@ repo forall -c 'git lfs pull' ...@@ -114,21 +117,22 @@ repo forall -c 'git lfs pull'
**表3** 版本新增特性表 **表3** 版本新增特性表
| 子系统名称 | 标准系统 | 轻量、小型系统 | | 子系统名称 | 标准系统 | 轻量、小型系统 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| 系统服务管理 | 新增添加群组校验机制。<br/>主要涉及如下需求:<br/>I52G5Q&nbsp;添加群组校验机制 | NA | | SDK | SDK区分Full SDK和Public SDK进行发布。<br/>*说明:API Version 8的Public SDK首次于7月6日单独更新发布。* | NA |
| 电源管理 | 实现兼容亮度调节和电池信息查询API接口能力。<br/>主要涉及如下需求:<br/>I526UP&nbsp;支持\@system.brightness亮度调节接口<br/>I526UP&nbsp;支持\@system.battery电池信息查询接口 | NA | | 系统服务管理 | 新增添加群组校验机制。<br/>主要涉及如下需求:<br/>I52G5Q&nbsp;添加群组校验机制 | NA |
| 包管理 | 实现查询指定应用是否安装接口能力。<br/>主要涉及如下需求:<br/>I56EWD&nbsp;支持对测试框架的配置<br/>I55RZJ&nbsp;查询指定应用是否安装 | NA | | 电源管理 | 实现兼容亮度调节和电池信息查询API接口能力。<br/>主要涉及如下需求:<br/>I526UP&nbsp;支持\@system.brightness亮度调节接口<br/>I526UP&nbsp;支持\@system.battery电池信息查询接口 | NA |
| 位置服务 | 实现兼容基本定位API接口能力。<br/>主要涉及如下需求:<br/>I53WFP&nbsp;支持基本定位能力,兼容system&nbsp;API | NA | | 包管理 | 实现查询指定应用是否安装接口能力。<br/>主要涉及如下需求:<br/>I56EWD&nbsp;支持对测试框架的配置<br/>I55RZJ&nbsp;查询指定应用是否安装 | NA |
| 元能力 | 实现FA模型支持查询/设置组件横竖屏状态、组件锁屏显示和组件启动亮屏。<br/>主要涉及如下需求:<br/>I56EH7&nbsp;FA模型支持查询/设置组件横竖屏状态<br/>I50D5Y&nbsp;FA模型支持组件锁屏显示<br/>I56EH7&nbsp;FA模型支持组件启动亮屏<br/>I55WB0&nbsp;卡片数据支持携带图片<br/>I55WB0&nbsp;FA卡片能力补齐-formManager重构<br/>I55WB0&nbsp;FA卡片能力补齐-支持卡片状态查询<br/>I55WB0&nbsp;FA卡片能力补齐-支持删除无效卡片<br/>I55WB0&nbsp;FA卡片能力补齐-支持卡片可见状态与更新状态单独设置<br/>I50D8H&nbsp;支持拦截uncatchedexception<br/>I50D91&nbsp;支持ANR(Application&nbsp;Not&nbsp;Response)处理 | NA | | 位置服务 | 实现兼容基本定位API接口能力。<br/>主要涉及如下需求:<br/>I53WFP&nbsp;支持基本定位能力,兼容system&nbsp;API | NA |
| 媒体 | 实现音频焦点、音频解码能力相关API接口能力。<br/>主要涉及如下需求:<br/>I56REO&nbsp;音频部件焦点/设备接口OH补齐<br/>I522W0&nbsp;支持amr格式音频编码枚举类型 | NA | | 元能力 | 实现FA模型支持查询/设置组件横竖屏状态、组件锁屏显示和组件启动亮屏。<br/>主要涉及如下需求:<br/>I56EH7&nbsp;FA模型支持查询/设置组件横竖屏状态<br/>I50D5Y&nbsp;FA模型支持组件锁屏显示<br/>I56EH7&nbsp;FA模型支持组件启动亮屏<br/>I55WB0&nbsp;卡片数据支持携带图片<br/>I55WB0&nbsp;FA卡片能力补齐-formManager重构<br/>I55WB0&nbsp;FA卡片能力补齐-支持卡片状态查询<br/>I55WB0&nbsp;FA卡片能力补齐-支持删除无效卡片<br/>I55WB0&nbsp;FA卡片能力补齐-支持卡片可见状态与更新状态单独设置<br/>I50D8H&nbsp;支持拦截uncatchedexception<br/>I50D91&nbsp;支持ANR(Application&nbsp;Not&nbsp;Response)处理 | NA |
| 窗口 | 支持对窗口属性进行设置。<br/>主要涉及如下需求:<br/>I56EH7&nbsp;支持窗口属性设置 | NA | | 媒体 | 实现音频焦点、音频解码能力相关API接口能力。<br/>主要涉及如下需求:<br/>I56REO&nbsp;音频部件焦点/设备接口OH补齐<br/>I522W0&nbsp;支持amr格式音频编码枚举类型 | NA |
| 网络管理 | 实现兼容WebSocket、fetch等API接口能力,支持以太网连接。<br/>主要涉及如下需求:<br/>I53CKH&nbsp;支持兼容\@system.fetch<br/>I53CJX&nbsp;支持兼容\@system.network<br/>I53CKT&nbsp;支持WebSocket<br/>I580PC&nbsp;支持以太网连接 | NA | | 窗口 | 支持对窗口属性进行设置。<br/>主要涉及如下需求:<br/>I56EH7&nbsp;支持窗口属性设置 | NA |
| Misc软件服务 | 实现兼容http文件下载API接口能力。<br/>主要涉及如下需求:<br/>I56Q4X&nbsp;支持文件下载接口 | NA | | 网络管理 | 实现兼容WebSocket、fetch等API接口能力,支持以太网连接。<br/>主要涉及如下需求:<br/>I53CKH&nbsp;支持兼容\@system.fetch<br/>I53CJX&nbsp;支持兼容\@system.network<br/>I53CKT&nbsp;支持WebSocket<br/>I580PC&nbsp;支持以太网连接 | NA |
| 事件通知 | 实现通知发送和取消的API接口能力。<br/>主要涉及如下需求:<br/>I50EEW&nbsp;通知发送和取消功能的接口能力补齐 | NA | | Misc软件服务 | 实现兼容http文件下载API接口能力。<br/>主要涉及如下需求:<br/>I56Q4X&nbsp;支持文件下载接口 | NA |
| 分布式数据管理 | 实现兼容\@system.storage&nbsp;API接口能力。<br/>主要涉及如下需求:<br/>I56RF3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;支持\@system.storage接口 | NA | | 事件通知 | 实现通知发送和取消的API接口能力。<br/>主要涉及如下需求:<br/>I50EEW&nbsp;通知发送和取消功能的接口能力补齐 | NA |
| 启动恢复 | 实现兼容\@system.device&nbsp;API接口能力。<br/>主要涉及如下需求:<br/>I56GBS&nbsp;支持\@system.device相关API | NA | | 分布式数据管理 | 实现兼容\@system.storage&nbsp;API接口能力。<br/>主要涉及如下需求:<br/>I56RF3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;支持\@system.storage接口 | NA |
| 应用 | 联系人支持第三方应用调用系统通话能力,提供用户基础通信能力。<br/>主要涉及如下需求:<br/>I58ZQ4&nbsp;联系人支持第三方应用调用系统通话能力 | NA | | 启动恢复 | 实现兼容\@system.device&nbsp;API接口能力。<br/>主要涉及如下需求:<br/>I56GBS&nbsp;支持\@system.device相关API | NA |
| 应用 | 联系人支持第三方应用调用系统通话能力,提供用户基础通信能力。<br/>主要涉及如下需求:<br/>I58ZQ4&nbsp;联系人支持第三方应用调用系统通话能力 | NA |
### API变更 ### API变更
...@@ -142,7 +146,7 @@ repo forall -c 'git lfs pull' ...@@ -142,7 +146,7 @@ repo forall -c 'git lfs pull'
## 修复缺陷列表 ## 修复缺陷列表
**表6** 修复缺陷ISSUE列表 **表4** 修复缺陷ISSUE列表
| ISSUE单 | 问题描述 | | ISSUE单 | 问题描述 |
| ------------------------------------------------------------ | ------------------------------------------------------------ | | ------------------------------------------------------------ | ------------------------------------------------------------ |
...@@ -153,7 +157,7 @@ repo forall -c 'git lfs pull' ...@@ -153,7 +157,7 @@ repo forall -c 'git lfs pull'
## 遗留缺陷列表 ## 遗留缺陷列表
**表7** 遗留缺陷列表 **表5** 遗留缺陷列表
| ISSUE | 问题描述 | 影响 | 计划解决日期 | | ISSUE | 问题描述 | 影响 | 计划解决日期 |
| ------------------------------------------------------------ | ---------------------------------------------------------- | ------------------------------------------------- | ------------ | | ------------------------------------------------------------ | ---------------------------------------------------------- | ------------------------------------------------- | ------------ |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册