“b3ce720010447d3729550d4473d3f35b096d3e6d”上不存在“git@gitcode.net:qq_30916377/VueJS.git”
提交 7bd363aa 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 a0631f1d
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## Introduction ## Introduction
The Socket Connection module allows an application to transmit data over a Socket connection through the TCP, UDP, or TLS protocol. The Socket Connection module allows an application to transmit data over a socket connection through the TCP, UDP, or TLS protocol.
## Basic Concepts ## Basic Concepts
...@@ -13,10 +13,11 @@ The Socket Connection module allows an application to transmit data over a Socke ...@@ -13,10 +13,11 @@ The Socket Connection module allows an application to transmit data over a Socke
## When to Use ## When to Use
Applications transmit data over TCP, UDP, or TLS Socket connections. The main application scenarios are as follows: Applications transmit data over TCP, UDP, or TLS socket connections. The main application scenarios are as follows:
- Implementing data transmission over TCP/UDP Socket connections - Implementing data transmission over TCP socket or UDP socket connections
- Implementing encrypted data transmission over TLS Socket connections - Implementing data transmission over TCP socket server connections
- Implementing encrypted data transmission over TLS socket connections
## Available APIs ## Available APIs
...@@ -28,72 +29,75 @@ Socket connection functions are mainly implemented by the **socket** module. The ...@@ -28,72 +29,75 @@ Socket connection functions are mainly implemented by the **socket** module. The
| -------- | -------- | | -------- | -------- |
| constructUDPSocketInstance() | Creates a **UDPSocket** object.| | constructUDPSocketInstance() | Creates a **UDPSocket** object.|
| constructTCPSocketInstance() | Creates a **TCPSocket** object.| | constructTCPSocketInstance() | Creates a **TCPSocket** object.|
| constructTCPSocketServerInstance() | Creates a **TCPSocketServer** object.|
| listen() | Listens for and accepts TCP socket connections established over the socket. (This API is applicable only to TCP.)|
| bind() | Binds the IP address and port number.| | bind() | Binds the IP address and port number.|
| send() | Sends data.| | send() | Sends data.|
| close() | Closes a Socket connection.| | close() | Closes a socket connection.|
| getState() | Obtains the Socket connection status.| | getState() | Obtains the socket connection status.|
| connect() | Connects to the specified IP address and port. This function is supported only for TCP.| | connect() | Connects to the specified IP address and port. This function is supported only for TCP.|
| getRemoteAddress() | Obtains the peer address of the Socket connection. This function is supported only for TCP. The **connect** API must have been called before you use this API.| | getRemoteAddress() | Obtains the peer address of the socket connection. This function is supported only for TCP. The **connect** API must have been called before you use this API.|
| on(type:&nbsp;'message') | Subscribes to **message** events of the Socket connection.| | setExtraOptions() | Sets other properties of the socket connection.|
| off(type:&nbsp;'message') | Unsubscribes from **message** events of the Socket connection.| | on(type:&nbsp;'message') | Subscribes to **message** events of the socket connection.|
| on(type:&nbsp;'close') | Subscribes to **close** events of the Socket connection.| | off(type:&nbsp;'message') | Unsubscribes from **message** events of the socket connection.|
| off(type:&nbsp;'close') | Unsubscribes from **close** events of the Socket connection.| | on(type:&nbsp;'close') | Subscribes to **close** events of the socket connection.|
| on(type:&nbsp;'error') | Subscribes to **error** events of the Socket connection.| | off(type:&nbsp;'close') | Unsubscribes from **close** events of the socket connection.|
| off(type:&nbsp;'error') | Unsubscribes from **error** events of the Socket connection.| | on(type:&nbsp;'error') | Subscribes to **error** events of the socket connection.|
| on(type:&nbsp;'listening') | Subscribes to **listening** events of the UDP Socket connection. | | off(type:&nbsp;'error') | Unsubscribes from **error** events of the socket connection.|
| off(type:&nbsp;'listening') | Unsubscribes from **listening** events of the UDP Socket connection. | | on(type:&nbsp;'listening') | Subscribes to **listening** events of the UDP socket connection. |
| on(type:&nbsp;'connect') | Subscribes to **connect** events of the TCP Socket connection. | | off(type:&nbsp;'listening') | Unsubscribes from **listening** events of the UDP socket connection. |
| off(type:&nbsp;'connect') | Unsubscribes from **connect** events of the TCP Socket connection.| | on(type:&nbsp;'connect') | Subscribes to **connect** events of the TCP socket connection. |
| off(type:&nbsp;'connect') | Unsubscribes from **connect** events of the TCP socket connection.|
TLS Socket connection functions are mainly provided by the **tls_socket** module. The following table describes the related APIs.
TLS socket connection functions are mainly provided by the **tls_socket** module. The following table describes the related APIs.
| API| Description| | API| Description|
| -------- | -------- | | -------- | -------- |
| constructTLSSocketInstance() | Creates a **TLSSocket** object.| | constructTLSSocketInstance() | Creates a **TLSSocket** object.|
| bind() | Binds the IP address and port number.| | bind() | Binds the IP address and port number.|
| close(type:&nbsp;'error') | Closes a Socket connection.| | close(type:&nbsp;'error') | Closes a socket connection.|
| connect() | Sets up a connection to the specified IP address and port number.| | connect() | Sets up a connection to the specified IP address and port number.|
| getCertificate() | Obtains an object representing the local certificate.| | getCertificate() | Obtains an object representing the local certificate.|
| getCipherSuite() | Obtains a list containing information about the negotiated cipher suite.| | getCipherSuite() | Obtains a list containing information about the negotiated cipher suite.|
| getProtocol() | Obtains a string containing the SSL/TLS protocol version negotiated for the current connection.| | getProtocol() | Obtains a string containing the SSL/TLS protocol version negotiated for the current connection.|
| getRemoteAddress() | Obtains the peer address of the TLS Socket connection.| | getRemoteAddress() | Obtains the peer address of the TLS socket connection.|
| getRemoteCertificate() | Obtains an object representing a peer certificate.| | getRemoteCertificate() | Obtains an object representing a peer certificate.|
| getSignatureAlgorithms() | Obtains a list containing signature algorithms shared between the server and client, in descending order of priority.| | getSignatureAlgorithms() | Obtains a list containing signature algorithms shared between the server and client, in descending order of priority.|
| getState() | Obtains the TLS Socket connection status.| | getState() | Obtains the TLS socket connection status.|
| off(type:&nbsp;'close') | Unsubscribes from **close** events of the TLS Socket connection.| | off(type:&nbsp;'close') | Unsubscribes from **close** events of the TLS socket connection.|
| off(type:&nbsp;'error') | Unsubscribes from **error** events of the TLS Socket connection.| | off(type:&nbsp;'error') | Unsubscribes from **error** events of the TLS socket connection.|
| off(type:&nbsp;'message') | Unsubscribes from **message** events of the TLS Socket connection.| | off(type:&nbsp;'message') | Unsubscribes from **message** events of the TLS socket connection.|
| on(type:&nbsp;'close') | Subscribes to **close** events of the TLS Socket connection.| | on(type:&nbsp;'close') | Subscribes to **close** events of the TLS socket connection.|
| on(type:&nbsp;'error') | Subscribes to **error** events of the TLS Socket connection.| | on(type:&nbsp;'error') | Subscribes to **error** events of the TLS socket connection.|
| on(type:&nbsp;'message') | Subscribes to **message** events of the TLS Socket connection.| | on(type:&nbsp;'message') | Subscribes to **message** events of the TLS socket connection.|
| send() | Sends data.| | send() | Sends data.|
| setExtraOptions() | Sets other properties of the TLS Socket connection.| | setExtraOptions() | Sets other properties of the TLS socket connection.|
## Transmitting Data over TCP/UDP Socket Connections ## Transmitting Data over TCP Socket or UDP Socket Connections
The implementation is similar for UDP Socket and TCP Socket connections. The following uses data transmission over a TCP Socket connection as an example. The implementation is similar for UDP socket and TCP socket connections. The following uses data transmission over a TCP socket connection as an example.
1. Import the required **socket** module. 1. Import the required **socket** module.
2. Create a **TCPSocket** object. 2. Create a TCP socket connection. A **TCPSocket** object is returned.
3. (Optional) Subscribe to TCP Socket connection events. 3. (Optional) Subscribe to TCP socket connection events.
4. Bind the IP address and port number. The port number can be specified or randomly allocated by the system. 4. Bind the IP address and port number. The port number can be specified or randomly allocated by the system.
5. Set up a connection to the specified IP address and port number. 5. Set up a connection to the specified IP address and port number.
6. Send data. 6. Send data over the connection.
7. Enable the TCP Socket connection to be automatically closed after use. 7. Enable the TCP socket connection to be automatically closed after use.
```js ```js
import socket from '@ohos.net.socket' import socket from '@ohos.net.socket'
// Create a TCPSocket object. // Create a TCP socket connection. A TCPSocket object is returned.
let tcp = socket.constructTCPSocketInstance(); let tcp = socket.constructTCPSocketInstance();
// Subscribe to TCP Socket connection events. // Subscribe to events of the TCPSocket object.
tcp.on('message', value => { tcp.on('message', value => {
console.log("on message") console.log("on message")
let buffer = value.message let buffer = value.message
...@@ -139,7 +143,7 @@ tcp.bind(bindAddress, err => { ...@@ -139,7 +143,7 @@ tcp.bind(bindAddress, err => {
} }
console.log('connect success'); console.log('connect success');
// Send data. // Send data over the connection.
tcp.send({ tcp.send({
data: 'Hello, server!' data: 'Hello, server!'
}, err => { }, err => {
...@@ -152,7 +156,7 @@ tcp.bind(bindAddress, err => { ...@@ -152,7 +156,7 @@ tcp.bind(bindAddress, err => {
}); });
}); });
// Enable the TCP Socket connection to be automatically closed after use. Then, disable listening for TCP Socket connection events. // Enable the socket connection to be automatically closed after use. Then, unsubscribe from events of the connection.
setTimeout(() => { setTimeout(() => {
tcp.close((err) => { tcp.close((err) => {
console.log('close socket.') console.log('close socket.')
...@@ -163,11 +167,92 @@ setTimeout(() => { ...@@ -163,11 +167,92 @@ setTimeout(() => {
}, 30 * 1000); }, 30 * 1000);
``` ```
## Implementing Data Transmission over TCP Socket Server Connections
### How to Develop
The TCP socket server connection process is described as follows:
1. Import the required **socket** module.
2. Create a TCP socket server connection. A **TCPSocketServer** object is returned.
3. Bind the local IP address and port, and listen for and accept TCP socket connections established over the socket.
4. Subscribe to **connect** events of the **TCPSocketServer** object to listen for client connection status changes.
5. Set up a connection between the client and the server. A **TCPSocketConnection** object is returned.
6. Subscribe to events of the **TCPSocketConnection** object, and send data to the client through the **TCPSocketConnection** object.
7. Close the connection between the client and the server.
8. Unsubscribe from events of the **TCPSocketConnection** and **TCPSocketServer** objects.
```js
import socket from '@ohos.net.socket'
// Create a TCP socket server connection. A TCPSocketServer object is returned.
let tcpServer = socket.constructTCPSocketServerInstance();
// Bind the local IP address and port number for listening.
tcpServer.listen({ address: "192.168.xx.xxx", port: xxxx, family: 1 }, err => {
if (err) {
console.log("listen fail");
return;
}
console.log("listen success");
})
// Subscribe to connect events of the TCPSocketServer object.
tcpServer.on('connect', function(client) {
// Subscribe to events of the TCPSocketConnection object.
client.on('close', () => {
console.log("on close success");
});
client.on('message', function(value) {
let buffer = value.message;
let dataView = new DataView(buffer);
let str = "";
for (let i = 0; i < dataView.byteLength; ++i) {
str += String.fromCharCode(dataView.getUint8(i));
}
console.log("received message--:" + str);
console.log("received address--:" + value.remoteInfo.address);
console.log("received family--:" + value.remoteInfo.family);
console.log("received port--:" + value.remoteInfo.port);
console.log("received size--:" + value.remoteInfo.size);
});
// Send data to the client.
client.send({data: 'Hello, client!'}, err => {
if (err) {
console.log('send fail');
return;
}
console.log('send success');
});
// Close the connection between the client and the server.
client.close(err => {
if (err) {
console.log('close fail');
return;
}
console.log('close success');
});
// Unsubscribe from events of the TCPSocketConnection object.
setTimeout(() => {
client.off('message');
client.off('close');
}, 10 * 1000);
});
// Unsubscribe from events of the TCPSocketServer object.
setTimeout(() => {
tcpServer.off('connect');
}, 30 * 1000);
```
## Implementing Encrypted Data Transmission over TLS Socket Connections ## Implementing Encrypted Data Transmission over TLS Socket Connections
### How to Develop ### How to Develop
TLS Socket connection process on the client: The TLSsocket connection process on the client is described as follows:
1. Import the required **socket** module. 1. Import the required **socket** module.
...@@ -175,21 +260,21 @@ TLS Socket connection process on the client: ...@@ -175,21 +260,21 @@ TLS Socket connection process on the client:
3. For two-way authentication, upload the client CA certificate and digital certificate. For one-way authentication, upload the client CA certificate. 3. For two-way authentication, upload the client CA certificate and digital certificate. For one-way authentication, upload the client CA certificate.
4. Create a **TLSSocket** object. 4. Create a TLS socket connection. A **TLSsocket** object is returned.
5. (Optional) Subscribe to TLS Socket connection events. 5. (Optional) Subscribe to TLS socket connection events.
6. Send data. 6. Send data over the connection.
7. Enable the TLS Socket connection to be automatically closed after use. 7. Enable the TLS socket connection to be automatically closed after use.
```js ```js
import socket from '@ohos.net.socket' import socket from '@ohos.net.socket'
// Create a TLS Socket connection (for two-way authentication). // Create a TLS socket connection (for two-way authentication). A TLSSocket object is returned.
let tlsTwoWay = socket.constructTLSSocketInstance(); let tlsTwoWay = socket.constructTLSSocketInstance();
// Subscribe to TLS Socket connection events. // Subscribe to TLS socket connection events.
tlsTwoWay.on('message', value => { tlsTwoWay.on('message', value => {
console.log("on message") console.log("on message")
let buffer = value.message let buffer = value.message
...@@ -246,7 +331,7 @@ tlsTwoWay.connect(options, (err, data) => { ...@@ -246,7 +331,7 @@ tlsTwoWay.connect(options, (err, data) => {
console.log(data); console.log(data);
}); });
// Enable the TCP Socket connection to be automatically closed after use. Then, disable listening for TCP Socket connection events. // Enable the socket connection to be automatically closed after use. Then, unsubscribe from events of the connection.
tlsTwoWay.close((err) => { tlsTwoWay.close((err) => {
if (err) { if (err) {
console.log("close callback error = " + err); console.log("close callback error = " + err);
...@@ -258,10 +343,10 @@ tlsTwoWay.close((err) => { ...@@ -258,10 +343,10 @@ tlsTwoWay.close((err) => {
tlsTwoWay.off('close'); tlsTwoWay.off('close');
}); });
// Create a TLS Socket connection (for one-way authentication). // Create a TLS socket connection (for one-way authentication). A TLSsocket object is returned.
let tlsOneWay = socket.constructTLSSocketInstance(); // One way authentication let tlsOneWay = socket.constructTLSSocketInstance(); // One way authentication
// Subscribe to TLS Socket connection events. // Subscribe to TLS socket connection events.
tlsTwoWay.on('message', value => { tlsTwoWay.on('message', value => {
console.log("on message") console.log("on message")
let buffer = value.message let buffer = value.message
...@@ -307,7 +392,7 @@ tlsOneWay.connect(oneWayOptions, (err, data) => { ...@@ -307,7 +392,7 @@ tlsOneWay.connect(oneWayOptions, (err, data) => {
console.log(data); console.log(data);
}); });
// Enable the TCP Socket connection to be automatically closed after use. Then, disable listening for TCP Socket connection events. // Enable the socket connection to be automatically closed after use. Then, unsubscribe from events of the connection.
tlsTwoWay.close((err) => { tlsTwoWay.close((err) => {
if (err) { if (err) {
console.log("close callback error = " + err); console.log("close callback error = " + err);
...@@ -319,11 +404,3 @@ tlsTwoWay.close((err) => { ...@@ -319,11 +404,3 @@ tlsTwoWay.close((err) => {
tlsTwoWay.off('close'); tlsTwoWay.off('close');
}); });
``` ```
## Samples
The following samples are provided to help you better understand how to develop Socket connection features:
- [`Socket`: Socket Connection (ArkTS) (API9)] (https://gitee.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/Connectivity/Socket)
- [UDP Socket (ArkTS) (API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/UdpDemoOH)
- [TCP Socket (ArkTS) (API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/TcpSocketDemo)
...@@ -14,7 +14,6 @@ The [i18n](js-apis-i18n.md) module provides enhanced i18n capabilities through s ...@@ -14,7 +14,6 @@ The [i18n](js-apis-i18n.md) module provides enhanced i18n capabilities through s
```js ```js
import Intl from '@ohos.intl'; import Intl from '@ohos.intl';
``` ```
Importing an incorrect bundle can lead to unexpected API behavior.
## Locale ## Locale
...@@ -34,7 +33,7 @@ Importing an incorrect bundle can lead to unexpected API behavior. ...@@ -34,7 +33,7 @@ Importing an incorrect bundle can lead to unexpected API behavior.
| collation | string | Yes | No | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**.| | collation | string | Yes | No | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**.|
| hourCycle | string | Yes | No | Time system for the locale. The value can be any of the following: **h12**, **h23**, **h11**, or **h24**.| | hourCycle | string | Yes | No | Time system for the locale. The value can be any of the following: **h12**, **h23**, **h11**, or **h24**.|
| numberingSystem | string | Yes | No | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.| | numberingSystem | string | Yes | No | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.|
| numeric | boolean | Yes | No | Whether to apply special collation rules for numeric characters. | | numeric | boolean | Yes | No | Whether to apply special collation rules for numeric characters. The default value is **false**. |
### constructor<sup>8+</sup> ### constructor<sup>8+</sup>
...@@ -67,7 +66,7 @@ Creates a **Locale** object. ...@@ -67,7 +66,7 @@ Creates a **Locale** object.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------------------- | -------------------------------- | ---- | ---------------------------- | | -------------------- | -------------------------------- | ---- | ---------------------------- |
| locale | string | Yes | A string containing locale information, including the language, optional script, and region. For details about the international standards and combination modes for the language, script, and country or region, see [intl Development](../../internationalization/intl-guidelines.md#setting-locale-information).| | locale | string | Yes | A string containing locale information, including the language, optional script, and region. For details about the international standards and combination modes for the language, script, and country or region, see [intl Development](../../internationalization/intl-guidelines.md#setting-locale-information).|
| options | [LocaleOptions](#localeoptions6) | No | Options for creating the **Locale** object. | | options | [LocaleOptions](#localeoptions6) | No | Options for creating the **Locale** object.|
**Example** **Example**
```js ```js
...@@ -162,7 +161,7 @@ Minimizes information of the **Locale** object. If the script and locale informa ...@@ -162,7 +161,7 @@ Minimizes information of the **Locale** object. If the script and locale informa
## LocaleOptions<sup>6+</sup> ## LocaleOptions<sup>6+</sup>
Represents the locale options. Represents the locale options.
In API version 9, the attributes in **LocaleOptions** are optional. Since API version 9, the attributes in **LocaleOptions** are optional.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
...@@ -172,7 +171,7 @@ In API version 9, the attributes in **LocaleOptions** are optional. ...@@ -172,7 +171,7 @@ In API version 9, the attributes in **LocaleOptions** are optional.
| collation | string | Yes | Yes | Collation rule. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **emoji**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **search**, **searchjl**, **standard**, **stroke**, **trad**, **unihan**, **zhuyin**.| | collation | string | Yes | Yes | Collation rule. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **emoji**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **search**, **searchjl**, **standard**, **stroke**, **trad**, **unihan**, **zhuyin**.|
| hourCycle | string | Yes | Yes | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, or **h24**.| | hourCycle | string | Yes | Yes | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, or **h24**.|
| numberingSystem | string | Yes | Yes | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.| | numberingSystem | string | Yes | Yes | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.|
| numeric | boolean | Yes | Yes | Whether to use the 12-hour clock. | | numeric | boolean | Yes | Yes | Whether to use the 12-hour clock. The default value is **false**. |
| caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.| | caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.|
...@@ -207,7 +206,7 @@ Creates a **DateTimeOptions** object for the specified locale. ...@@ -207,7 +206,7 @@ Creates a **DateTimeOptions** object for the specified locale.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------------------- | ------------------------------------ | ---- | ---------------------------- | | -------------------- | ------------------------------------ | ---- | ---------------------------- |
| locale | string \| Array&lt;string&gt; | Yes | A string containing locale information, including the language, optional script, and region.| | locale | string \| Array&lt;string&gt; | Yes | A string containing locale information, including the language, optional script, and region.|
| options | [DateTimeOptions](#datetimeoptions6) | No | Options for creating a **DateTimeFormat** object. | | options | [DateTimeOptions](#datetimeoptions6) | No | Options for creating a **DateTimeFormat** object. If no options are set, the default values of **year**, **month**, and **day** are **numeric**.|
**Example** **Example**
```js ```js
...@@ -314,7 +313,7 @@ Obtains the formatting options for **DateTimeFormat** object. ...@@ -314,7 +313,7 @@ Obtains the formatting options for **DateTimeFormat** object.
## DateTimeOptions<sup>6+</sup> ## DateTimeOptions<sup>6+</sup>
Provides the options for the **DateTimeFormat** object. Provides the options for the **DateTimeFormat** object.
In API version 9, the attributes in **DateTimeOptions** are optional. Since API version 9, the attributes in **DateTimeOptions** are optional.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
...@@ -326,7 +325,7 @@ In API version 9, the attributes in **DateTimeOptions** are optional. ...@@ -326,7 +325,7 @@ In API version 9, the attributes in **DateTimeOptions** are optional.
| hourCycle | string | Yes | Yes | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, or **h24**.| | hourCycle | string | Yes | Yes | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, or **h24**.|
| timeZone | string | Yes | Yes | Time zone represented by a valid IANA time zone ID. | | timeZone | string | Yes | Yes | Time zone represented by a valid IANA time zone ID. |
| numberingSystem | string | Yes | Yes | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.| | numberingSystem | string | Yes | Yes | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.|
| hour12 | boolean | Yes | Yes | Whether to use the 12-hour clock. | | hour12 | boolean | Yes | Yes | Whether to use the 12-hour clock. If **hour12** and **hourCycle** are not set and the 24-hour clock is turned on, the default value of **hour12** is **false**. |
| weekday | string | Yes | Yes | Workday display format. The value can be **long**, **short**, or **narrow**.| | weekday | string | Yes | Yes | Workday display format. The value can be **long**, **short**, or **narrow**.|
| era | string | Yes | Yes | Era display format. The value can be **long**, **short**, or **narrow**.| | era | string | Yes | Yes | Era display format. The value can be **long**, **short**, or **narrow**.|
| year | string | Yes | Yes | Year display format. The value can be **numeric** or **2-digit**. | | year | string | Yes | Yes | Year display format. The value can be **numeric** or **2-digit**. |
...@@ -438,31 +437,31 @@ Obtains the options of the **NumberFormat** object. ...@@ -438,31 +437,31 @@ Obtains the options of the **NumberFormat** object.
## NumberOptions<sup>6+</sup> ## NumberOptions<sup>6+</sup>
Defines the device capability. Defines the device capability.
In API version 9, the attributes in **NumberOptions** are optional. Since API version 9, the attributes in **NumberOptions** are optional.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| ------------------------ | ------- | ---- | ---- | ---------------------------------------- | | ------------------------ | ------- | ---- | ---- | ---------------------------------------- |
| locale | string | Yes | No | Locale, for example, **zh-Hans-CN**. | | locale | string | Yes | No | Locale, for example, **zh-Hans-CN**. The default value is the system locale. |
| currency | string | Yes | Yes | Currency unit, for example, **EUR**, **CNY**, or **USD**. | | currency | string | Yes | Yes | Currency unit, for example, **EUR**, **CNY**, or **USD**. |
| currencySign | string | Yes | Yes | Currency unit symbol. The value can be **symbol**, **narrowSymbol**, **code**, or **name**.| | currencySign | string | Yes | Yes | Currency unit symbol. The value can be **symbol**, **narrowSymbol**, **code**, or **name**. The default value is **symbol**.|
| currencyDisplay | string | Yes | Yes | Currency display mode. The value can be **symbol**, **narrowSymbol**, **code**, or **name**.| | currencyDisplay | string | Yes | Yes | Currency display mode. The value can be **symbol**, **narrowSymbol**, **code**, or **name**. The default value is **symbol**.|
| unit | string | Yes | Yes | Unit name, for example, **meter**, **inch**, or **hectare**. | | unit | string | Yes | Yes | Unit name, for example, **meter**, **inch**, or **hectare**. |
| unitDisplay | string | Yes | Yes | Unit display format. The value can be **long**, **short**, or **narrow**.| | unitDisplay | string | Yes | Yes | Unit display format. The value can be **long**, **short**, or **narrow**. The default value is **short**.|
| unitUsage<sup>8+</sup> | string | Yes | Yes | Unit usage scenario. The value can be any of the following: **default**, **area-land-agricult**, **area-land-commercl**, **area-land-residntl**, **length-person**, **length-person-small**, **length-rainfall**, **length-road**, **length-road-small**, **length-snowfall**, **length-vehicle**, **length-visiblty**, **length-visiblty-small**, **length-person-informal**, **length-person-small-informal**, **length-road-informal**, **speed-road-travel**, **speed-wind**, **temperature-person**, **temperature-weather**, **volume-vehicle-fuel**.| | unitUsage<sup>8+</sup> | string | Yes | Yes | Unit usage scenario. The value can be any of the following: **default**, **area-land-agricult**, **area-land-commercl**, **area-land-residntl**, **length-person**, **length-person-small**, **length-rainfall**, **length-road**, **length-road-small**, **length-snowfall**, **length-vehicle**, **length-visiblty**, **length-visiblty-small**, **length-person-informal**, **length-person-small-informal**, **length-road-informal**, **speed-road-travel**, **speed-wind**, **temperature-person**, **temperature-weather**, **volume-vehicle-fuel**. The default value is **default**.|
| signDisplay | string | Yes | Yes | Number sign display format. The value can be **auto**, **never**, **always**, or **expectZero**.| | signDisplay | string | Yes | Yes | Number sign display format. The value can be **auto**, **never**, **always**, or **expectZero**. The default value is **auto**.|
| compactDisplay | string | Yes | Yes | Compact display format. The value can be **long** or **short**. | | compactDisplay | string | Yes | Yes | Compact display format. The value can be **long** or **short**. The default value is **short**. |
| notation | string | Yes | Yes | Number formatting specification. The value can be **standard**, **scientific**, **engineering**, or **compact**.| | notation | string | Yes | Yes | Number formatting specification. The value can be **standard**, **scientific**, **engineering**, or **compact**. The default value is **standard**.|
| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.| | localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. The default value is **best fit**.|
| style | string | Yes | Yes | Number display format. The value can be **decimal**, **currency**, **percent**, or **unit**.| | style | string | Yes | Yes | Number display format. The value can be **decimal**, **currency**, **percent**, or **unit**. The default value is **decimal**.|
| numberingSystem | string | Yes | Yes | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.| | numberingSystem | string | Yes | Yes | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**. The default value is the default numbering system of the specified locale.|
| useGrouping | boolean | Yes | Yes | Whether to use grouping for display. | | useGrouping | boolean | Yes | Yes | Whether to use grouping for display. The default value is **auto**. |
| minimumIntegerDigits | number | Yes | Yes | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. | | minimumIntegerDigits | number | Yes | Yes | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. The default value of is **1**. |
| minimumFractionDigits | number | Yes | Yes | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. | | minimumFractionDigits | number | Yes | Yes | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. The default value is **0**. |
| maximumFractionDigits | number | Yes | Yes | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**. | | maximumFractionDigits | number | Yes | Yes | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**. The default value is **3**. |
| minimumSignificantDigits | number | Yes | Yes | Minimum number of the least significant digits. The value ranges from **1** to **21**. | | minimumSignificantDigits | number | Yes | Yes | Minimum number of the least significant digits. The value ranges from **1** to **21**. The default value of is **1**. |
| maximumSignificantDigits | number | Yes | Yes | Maximum number of the least significant digits. The value ranges from **1** to **21**. | | maximumSignificantDigits | number | Yes | Yes | Maximum number of the least significant digits. The value ranges from **1** to **21**. The default value is **21**. |
## Collator<sup>8+</sup> ## Collator<sup>8+</sup>
...@@ -496,7 +495,7 @@ Creates a **Collator** object. ...@@ -496,7 +495,7 @@ Creates a **Collator** object.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------------------- | ------------------------------------ | ---- | ---------------------------- | | -------------------- | ------------------------------------ | ---- | ---------------------------- |
| locale | string \| Array&lt;string&gt; | Yes | A string containing locale information, including the language, optional script, and region.| | locale | string \| Array&lt;string&gt; | Yes | A string containing locale information, including the language, optional script, and region.|
| options | [CollatorOptions](#collatoroptions8) | No | Options for creating a **Collator** object. | | options | [CollatorOptions](#collatoroptions8) | No | Options for creating a **Collator** object. |
**Example** **Example**
```js ```js
...@@ -562,19 +561,19 @@ Returns properties reflecting the locale and collation options of a **Collator** ...@@ -562,19 +561,19 @@ Returns properties reflecting the locale and collation options of a **Collator**
## CollatorOptions<sup>8+</sup> ## CollatorOptions<sup>8+</sup>
Represents the properties of a **Collator** object. Represents the properties of a **Collator** object.
In API version 9, the attributes in **CollatorOptions** are optional. Since API version 9, the attributes in **CollatorOptions** are optional.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| ----------------- | ------- | ---- | ---- | ---------------------------------------- | | ----------------- | ------- | ---- | ---- | ---------------------------------------- |
| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.| | localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. The default value is **best fit**.|
| usage | string | Yes | Yes | Whether the comparison is for sorting or for searching. The value can be **sort** or **search**. | | usage | string | Yes | Yes | Whether the comparison is for sorting or for searching. The value can be **sort** or **search**. The default value is **sort**. |
| sensitivity | string | Yes | Yes | Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **letiant**.| | sensitivity | string | Yes | Yes | Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **letiant**. The default value is **variant**.|
| ignorePunctuation | boolean | Yes | Yes | Whether punctuation is ignored. The value can be **true** or **false**. | | ignorePunctuation | boolean | Yes | Yes | Whether punctuation is ignored. The value can be **true** or **false**. The default value is **false**. |
| collation | string | Yes | Yes | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**.| | collation | string | Yes | Yes | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**. The default value is **default**.|
| numeric | boolean | Yes | Yes | Whether numeric collation is used. The value can be **true** or **false**. | | numeric | boolean | Yes | Yes | Whether numeric collation is used. The value can be **true** or **false**. The default value is **false**. |
| caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.| | caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**. The default value is **false**.|
## PluralRules<sup>8+</sup> ## PluralRules<sup>8+</sup>
...@@ -608,7 +607,7 @@ Creates a **PluralRules** object to obtain the singular-plural type of numbers. ...@@ -608,7 +607,7 @@ Creates a **PluralRules** object to obtain the singular-plural type of numbers.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------------------- | ---------------------------------------- | ---- | ---------------------------- | | -------------------- | ---------------------------------------- | ---- | ---------------------------- |
| locale | string \| Array&lt;string&gt; | Yes | A string containing locale information, including the language, optional script, and region.| | locale | string \| Array&lt;string&gt; | Yes | A string containing locale information, including the language, optional script, and region.|
| options | [PluralRulesOptions](#pluralrulesoptions8) | No | Options for creating a **PluralRules** object. | | options | [PluralRulesOptions](#pluralrulesoptions8) | No | Options for creating a **PluralRules** object. |
**Example** **Example**
```js ```js
...@@ -654,19 +653,19 @@ Obtains a string that represents the singular-plural type of the specified numbe ...@@ -654,19 +653,19 @@ Obtains a string that represents the singular-plural type of the specified numbe
## PluralRulesOptions<sup>8+</sup> ## PluralRulesOptions<sup>8+</sup>
Represents the properties of a **PluralRules** object. Represents the properties of a **PluralRules** object.
In API version 9, the attributes in **PluralRulesOptions** are optional. Since API version 9, the attributes in **PluralRulesOptions** are optional.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| ------------------------ | ------ | ---- | ---- | ---------------------------------------- | | ------------------------ | ------ | ---- | ---- | ---------------------------------------- |
| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.| | localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. The default value is **best fit**.|
| type | string | Yes | Yes | Sorting type. The value can be **cardinal** or **ordinal**. | | type | string | Yes | Yes | Sorting type. The value can be **cardinal** or **ordinal**. The default value is **cardinal**. |
| minimumIntegerDigits | number | Yes | Yes | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. | | minimumIntegerDigits | number | Yes | Yes | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. The default value of is **1**. |
| minimumFractionDigits | number | Yes | Yes | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. | | minimumFractionDigits | number | Yes | Yes | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. The default value is **0**. |
| maximumFractionDigits | number | Yes | Yes | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**. | | maximumFractionDigits | number | Yes | Yes | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**. The default value is **3**. |
| minimumSignificantDigits | number | Yes | Yes | Minimum number of the least significant digits. The value ranges from **1** to **21**. | | minimumSignificantDigits | number | Yes | Yes | Minimum number of the least significant digits. The value ranges from **1** to **21**. The default value of is **1**. |
| maximumSignificantDigits | number | Yes | Yes | Maximum number of the least significant digits. The value ranges from **1** to **21**. | | maximumSignificantDigits | number | Yes | Yes | Maximum number of the least significant digits. The value ranges from **1** to **21**. The default value is **21**. |
## RelativeTimeFormat<sup>8+</sup> ## RelativeTimeFormat<sup>8+</sup>
...@@ -795,15 +794,14 @@ Obtains the formatting options for **RelativeTimeFormat** objects. ...@@ -795,15 +794,14 @@ Obtains the formatting options for **RelativeTimeFormat** objects.
## RelativeTimeFormatInputOptions<sup>8+</sup> ## RelativeTimeFormatInputOptions<sup>8+</sup>
Represents the properties of a **RelativeTimeFormat** object. Represents the properties of a **RelativeTimeFormat** object.
In API version 9, the attributes in **RelativeTimeFormatInputOptions** are optional. Since API version 9, the attributes in **RelativeTimeFormatInputOptions** are optional.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| ------------- | ------ | ---- | ---- | ---------------------------------------- | | ------------- | ------ | ---- | ---- | ---------------------------------------- |
| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.| | localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. The default value is **best fit**.|
| numeric | string | Yes | Yes | Format of the output message. The value can be **always** or **auto**. | | numeric | string | Yes | Yes | Format of the output message. The value can be **always** or **auto**. The default value is **always**. |
| style | string | Yes | Yes | Length of an internationalized message. The value can be **long**, **short**, or **narrow**.| | style | string | Yes | Yes | Length of an internationalized message. The value can be **long**, **short**, or **narrow**. The default value is **long**.|
## RelativeTimeFormatResolvedOptions<sup>8+</sup> ## RelativeTimeFormatResolvedOptions<sup>8+</sup>
......
# @ohos.ai.mindSporeLite (Inference) # @ohos.ai.mindSporeLite (Inference)
MindSpore Lite is an AI engine that implements AI model inference for different hardware devices. It has been used in a wide range of fields, such as image classification, target recognition, facial recognition, and character recognition. MindSpore Lite is an AI engine that implements AI model inference for different hardware devices. It has been used in a wide range of fields, such as image classification, target recognition, facial recognition, and character recognition.
The **mindSporeLite** module provides APIs for the MindSpore Lite inference engine to implment model inference. The **mindSporeLite** module provides APIs for the MindSpore Lite inference engine to implement model inference.
> **NOTE** > **NOTE**
> >
...@@ -48,7 +48,7 @@ Defines the CPU backend device option. ...@@ -48,7 +48,7 @@ Defines the CPU backend device option.
| threadNum | number | Yes | Yes | Number of runtime threads. The default value is **2**. | | threadNum | number | Yes | Yes | Number of runtime threads. The default value is **2**. |
| threadAffinityMode | [ThreadAffinityMode](#threadaffinitymode) | Yes | Yes | Affinity mode for binding runtime threads to CPU cores. The default value is **mindSporeLite.ThreadAffinityMode.NO_AFFINITIES**.| | threadAffinityMode | [ThreadAffinityMode](#threadaffinitymode) | Yes | Yes | Affinity mode for binding runtime threads to CPU cores. The default value is **mindSporeLite.ThreadAffinityMode.NO_AFFINITIES**.|
| threadAffinityCoreList | number[] | Yes | Yes | List of CPU cores bound to runtime threads. Set this parameter only when **threadAffinityMode** is set. If **threadAffinityMode** is set to **mindSporeLite.ThreadAffinityMode.NO_AFFINITIES**, this parameter is empty. The number in the list indicates the SN of the CPU core. The default value is **[]**.| | threadAffinityCoreList | number[] | Yes | Yes | List of CPU cores bound to runtime threads. Set this parameter only when **threadAffinityMode** is set. If **threadAffinityMode** is set to **mindSporeLite.ThreadAffinityMode.NO_AFFINITIES**, this parameter is empty. The number in the list indicates the SN of the CPU core. The default value is **[]**.|
| precisionMode | string | Yes | Yes | Whether to enable the Float16 inference mode. The value **preferred_fp16** means to enable half-precision inference and the default value **force_fp32** means to disable half-precision inference. Other settings are not supported.| | precisionMode | string | Yes | Yes | Whether to enable the Float16 inference mode. The value **preferred_fp16** means to enable half-precision inference and the default value **enforce_fp32** means to disable half-precision inference. Other settings are not supported.|
**Float16 inference mode**: a mode that uses half-precision inference. Float16 uses 16 bits to represent a number and therefore it is also called half-precision. **Float16 inference mode**: a mode that uses half-precision inference. Float16 uses 16 bits to represent a number and therefore it is also called half-precision.
...@@ -125,7 +125,7 @@ Loads the input model from the full path for model inference. This API uses an a ...@@ -125,7 +125,7 @@ Loads the input model from the full path for model inference. This API uses an a
```js ```js
let context: mindSporeLite.Context = {}; let context: mindSporeLite.Context = {};
let context = {'target': ['cpu']}; context = {'target': ['cpu']};
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
mindSporeLite.loadModelFromFile(model_file, context, (result) => { mindSporeLite.loadModelFromFile(model_file, context, (result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
...@@ -181,17 +181,17 @@ Loads the input model from the memory for inference. This API uses an asynchrono ...@@ -181,17 +181,17 @@ Loads the input model from the memory for inference. This API uses an asynchrono
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State modelName: string = 'xxx.ms'; let modelName = '/path/to/xxx.ms';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.modelName).then((buffer) => { syscontext.resourceManager.getRawFileContent(modelName).then((buffer) => {
this.modelBuffer = buffer; let modelBuffer = buffer;
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (result) => {
const modelInputs = result.getInputs();
console.log(modelInputs[0].name);
})
}).catch(error => { }).catch(error => {
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.'); console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.');
}) })
mindSporeLite.loadModelFromBuffer(this.modelBuffer.buffer, (result) => {
const modelInputs = result.getInputs();
console.log(modelInputs[0].name);
})
``` ```
## mindSporeLite.loadModelFromBuffer ## mindSporeLite.loadModelFromBuffer
...@@ -213,19 +213,19 @@ Loads the input model from the memory for inference. This API uses an asynchrono ...@@ -213,19 +213,19 @@ Loads the input model from the memory for inference. This API uses an asynchrono
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State modelName: string = 'xxx.ms'; let modelName = '/path/to/xxx.ms';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.modelName).then((error,buffer) => { syscontext.resourceManager.getRawFileContent(modelName).then((error,buffer) => {
this.modelBuffer = buffer; let modelBuffer = buffer;
let context: mindSporeLite.Context = {};
context = {'target': ['cpu']};
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, context, (result) => {
const modelInputs = result.getInputs();
console.log(modelInputs[0].name);
})
}).catch(error => { }).catch(error => {
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.'); console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.');
}) })
let context: mindSporeLite.Context = {};
context = {'target': ['cpu']};
mindSporeLite.loadModelFromBuffer(this.modelBuffer.buffer, context, (result) => {
const modelInputs = result.getInputs();
console.log(modelInputs[0].name);
})
``` ```
## mindSporeLite.loadModelFromBuffer ## mindSporeLite.loadModelFromBuffer
...@@ -252,17 +252,17 @@ Loads the input model from the memory for inference. This API uses a promise to ...@@ -252,17 +252,17 @@ Loads the input model from the memory for inference. This API uses a promise to
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State modelName: string = 'xxx.ms'; let modelName = '/path/to/xxx.ms';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.modelName).then((buffer) => { syscontext.resourceManager.getRawFileContent(modelName).then((buffer) => {
this.modelBuffer = buffer; let modelBuffer = buffer;
mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then((result) => {
const modelInputs = result.getInputs();
console.log(modelInputs[0].name);
})
}).catch(error => { }).catch(error => {
console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.'); console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.');
}) })
mindSporeLite.loadModelFromBuffer(model_file).then((result) => {
const modelInputs = result.getInputs();
console.log(modelInputs[0].name);
})
``` ```
## mindSporeLite.loadModelFromFd ## mindSporeLite.loadModelFromFd
...@@ -284,7 +284,7 @@ Loads the input model based on the specified file descriptor for inference. This ...@@ -284,7 +284,7 @@ Loads the input model based on the specified file descriptor for inference. This
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let file = await fs.open(model_file, 0); let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY);
mindSporeLite.loadModelFromFd(file.fd, (result) => { mindSporeLite.loadModelFromFd(file.fd, (result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
console.log(modelInputs[0].name); console.log(modelInputs[0].name);
...@@ -313,7 +313,7 @@ import fs from '@ohos.file.fs'; ...@@ -313,7 +313,7 @@ import fs from '@ohos.file.fs';
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let context : mindSporeLite.Context = {}; let context : mindSporeLite.Context = {};
context = {'target': ['cpu']}; context = {'target': ['cpu']};
let file = await fs.open(model_file, 0); let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY);
mindSporeLite.loadModelFromFd(file.fd, context, (result) => { mindSporeLite.loadModelFromFd(file.fd, context, (result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
console.log(modelInputs[0].name); console.log(modelInputs[0].name);
...@@ -345,7 +345,7 @@ Loads the input model based on the specified file descriptor for inference. This ...@@ -345,7 +345,7 @@ Loads the input model based on the specified file descriptor for inference. This
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let file = await fs.open(model_file, 0); let file = fs.openSync(model_file, fs.OpenMode.READ_ONLY);
let mindSporeLiteModel = await mindSporeLite.loadModelFromFd(file.fd); let mindSporeLiteModel = await mindSporeLite.loadModelFromFd(file.fd);
mindSporeLite.loadModelFromFd(file.fd).then((result) => { mindSporeLite.loadModelFromFd(file.fd).then((result) => {
const modelInputs = result.getInputs(); const modelInputs = result.getInputs();
...@@ -383,9 +383,9 @@ mindSporeLite.loadModelFromFile(model_file).then((result) => { ...@@ -383,9 +383,9 @@ mindSporeLite.loadModelFromFile(model_file).then((result) => {
``` ```
### predict ### predict
predict(inputs: MSTensor[], callback: Callback&lt;Model&gt;): void predict(inputs: MSTensor[], callback: Callback&lt;MSTensor[]&gt;): void
Executes the inference model. This API uses an asynchronous callback to return the result. Executes the inference model. This API uses an asynchronous callback to return the result. Ensure that the model object is not reclaimed when being invoked.
**System capability**: SystemCapability.AI.MindSporeLite **System capability**: SystemCapability.AI.MindSporeLite
...@@ -394,20 +394,20 @@ Executes the inference model. This API uses an asynchronous callback to return t ...@@ -394,20 +394,20 @@ Executes the inference model. This API uses an asynchronous callback to return t
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | -------------------------- | | ------ | ----------------------- | ---- | -------------------------- |
| inputs | [MSTensor](#mstensor)[] | Yes | Model input, which is an **MSTensor** object.| | inputs | [MSTensor](#mstensor)[] | Yes | Model input, which is an **MSTensor** object.|
| callback | Callback<[Model](#model)> | Yes | Callback used to return the result, which is a **Model** object.| | callback | Callback<[MSTensor](#mstensor)[]> | Yes | Callback used to return the result, **MSTensor** object.|
**Example** **Example**
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State inputName: string = 'input_data.bin'; let inputName = 'input_data.bin';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
this.inputBuffer = buffer; let inputBuffer = buffer;
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file);
const modelInputs = mindSporeLiteModel.getInputs(); const modelInputs = mindSporeLiteModel.getInputs();
modelInputs[0].setData(this.inputBuffer.buffer); modelInputs[0].setData(inputBuffer.buffer);
result.predict(modelInputs, (result) => { result.predict(modelInputs, (result) => {
let output = new Float32Array(result[0].getData()); let output = new Float32Array(result[0].getData());
for (let i = 0; i < output.length; i++) { for (let i = 0; i < output.length; i++) {
...@@ -420,7 +420,7 @@ syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { ...@@ -420,7 +420,7 @@ syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => {
predict(inputs: MSTensor[]): Promise&lt;MSTensor[]&gt; predict(inputs: MSTensor[]): Promise&lt;MSTensor[]&gt;
Executes the inference model. This API uses a promise to return the result. Executes the inference model. This API uses a promise to return the result. Ensure that the model object is not reclaimed when being invoked.
**System capability**: SystemCapability.AI.MindSporeLite **System capability**: SystemCapability.AI.MindSporeLite
...@@ -440,14 +440,14 @@ Executes the inference model. This API uses a promise to return the result. ...@@ -440,14 +440,14 @@ Executes the inference model. This API uses a promise to return the result.
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State inputName: string = 'input_data.bin'; let inputName = 'input_data.bin';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
this.inputBuffer = buffer; let inputBuffer = buffer;
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file);
const modelInputs = mindSporeLiteModel.getInputs(); const modelInputs = mindSporeLiteModel.getInputs();
modelInputs[0].setData(this.inputBuffer.buffer); modelInputs[0].setData(inputBuffer.buffer);
result.predict(modelInputs).then((result) => { result.predict(modelInputs).then((result) => {
let output = new Float32Array(result[0].getData()); let output = new Float32Array(result[0].getData());
for (let i = 0; i < output.length; i++) { for (let i = 0; i < output.length; i++) {
...@@ -541,14 +541,14 @@ Obtains tensor data. ...@@ -541,14 +541,14 @@ Obtains tensor data.
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State inputName: string = 'input_data.bin'; let inputName = 'input_data.bin';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
this.inputBuffer = buffer; let inputBuffer = buffer;
let model_file = '/path/to/xxx.ms'; let model_file = '/path/to/xxx.ms';
let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file); let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file);
const modelInputs = mindSporeLiteModel.getInputs(); const modelInputs = mindSporeLiteModel.getInputs();
modelInputs[0].setData(this.inputBuffer.buffer); modelInputs[0].setData(inputBuffer.buffer);
result.predict(modelInputs).then((result) => { result.predict(modelInputs).then((result) => {
let output = new Float32Array(result[0].getData()); let output = new Float32Array(result[0].getData());
for (let i = 0; i < output.length; i++) { for (let i = 0; i < output.length; i++) {
...@@ -576,15 +576,15 @@ Sets the tensor data. ...@@ -576,15 +576,15 @@ Sets the tensor data.
```js ```js
import resourceManager from '@ohos.resourceManager' import resourceManager from '@ohos.resourceManager'
@State inputName: string = 'input_data.bin'; let inputName = 'input_data.bin';
let syscontext = globalThis.context; let syscontext = globalThis.context;
syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => {
this.inputBuffer = buffer; inputBuffer = buffer;
let model_file = '/path/to/xxx.ms';
let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file);
const modelInputs = mindSporeLiteModel.getInputs();
modelInputs[0].setData(inputBuffer.buffer);
}) })
let model_file = '/path/to/xxx.ms';
let mindSporeLiteModel = await mindSporeLite.loadModelFromFile(model_file);
const modelInputs = mindSporeLiteModel.getInputs();
modelInputs[0].setData(this.inputBuffer.buffer);
``` ```
## DataType ## DataType
......
...@@ -35,10 +35,10 @@ getResourceManager(callback: AsyncCallback&lt;ResourceManager&gt;): void ...@@ -35,10 +35,10 @@ getResourceManager(callback: AsyncCallback&lt;ResourceManager&gt;): void
Obtains the **ResourceManager** object of this application. This API uses an asynchronous callback to return the result. Obtains the **ResourceManager** object of this application. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the FA model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -52,7 +52,7 @@ Obtains the **ResourceManager** object of this application. This API uses an asy ...@@ -52,7 +52,7 @@ Obtains the **ResourceManager** object of this application. This API uses an asy
console.log("error is " + error); console.log("error is " + error);
return; return;
} }
mgr.getString(0x1000000, (error, value) => { mgr.getStringValue(0x1000000, (error, value) => {
if (error != null) { if (error != null) {
console.log("error is " + error); console.log("error is " + error);
} else { } else {
...@@ -70,10 +70,10 @@ getResourceManager(bundleName: string, callback: AsyncCallback&lt;ResourceManage ...@@ -70,10 +70,10 @@ getResourceManager(bundleName: string, callback: AsyncCallback&lt;ResourceManage
Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses an asynchronous callback to return the result. Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses an asynchronous callback to return the result.
**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the FA model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -94,10 +94,10 @@ getResourceManager(): Promise&lt;ResourceManager&gt; ...@@ -94,10 +94,10 @@ getResourceManager(): Promise&lt;ResourceManager&gt;
Obtains the **ResourceManager** object of this application. This API uses a promise to return the result. Obtains the **ResourceManager** object of this application. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the FA model.
**Return value** **Return value**
| Type | Description | | Type | Description |
...@@ -107,7 +107,7 @@ Obtains the **ResourceManager** object of this application. This API uses a prom ...@@ -107,7 +107,7 @@ Obtains the **ResourceManager** object of this application. This API uses a prom
**Example** **Example**
```js ```js
resourceManager.getResourceManager().then(mgr => { resourceManager.getResourceManager().then(mgr => {
mgr.getString(0x1000000, (error, value) => { mgr.getStringValue(0x1000000, (error, value) => {
if (error != null) { if (error != null) {
console.log("error is " + error); console.log("error is " + error);
} else { } else {
...@@ -127,10 +127,10 @@ getResourceManager(bundleName: string): Promise&lt;ResourceManager&gt; ...@@ -127,10 +127,10 @@ getResourceManager(bundleName: string): Promise&lt;ResourceManager&gt;
Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses a promise to return the result. Obtains the **ResourceManager** object of an application based on the specified bundle name. This API uses a promise to return the result.
**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the FA model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -185,7 +185,7 @@ try { ...@@ -185,7 +185,7 @@ try {
console.log("systemResourceManager getStringValue promise error is " + error); console.log("systemResourceManager getStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`systemResourceManager getStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`systemResourceManager getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -247,16 +247,6 @@ Defines the device configuration. ...@@ -247,16 +247,6 @@ Defines the device configuration.
| direction | [Direction](#direction) | Yes | No | Screen direction of the device.| | direction | [Direction](#direction) | Yes | No | Screen direction of the device.|
| locale | string | Yes | No | Current system language. | | locale | string | Yes | No | Current system language. |
**Example**
```js
resourceManager.getResourceManager((error, mgr) => {
mgr.getConfiguration((error, value) => {
let direction = value.direction;
let locale = value.locale;
});
});
```
## DeviceCapability ## DeviceCapability
...@@ -271,16 +261,6 @@ Defines the device capability. ...@@ -271,16 +261,6 @@ Defines the device capability.
| screenDensity | [ScreenDensity](#screendensity) | Yes | No | Screen density of the device.| | screenDensity | [ScreenDensity](#screendensity) | Yes | No | Screen density of the device.|
| deviceType | [DeviceType](#devicetype) | Yes | No | Type of the device. | | deviceType | [DeviceType](#devicetype) | Yes | No | Type of the device. |
**Example**
```js
resourceManager.getResourceManager((error, mgr) => {
mgr.getDeviceCapability((error, value) => {
let screenDensity = value.screenDensity;
let deviceType = value.deviceType;
});
});
```
## RawFileDescriptor<sup>8+</sup> ## RawFileDescriptor<sup>8+</sup>
...@@ -357,7 +337,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -357,7 +337,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -401,7 +381,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -401,7 +381,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringValue promise error is " + error); console.log("getStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -414,6 +394,8 @@ Obtains the string corresponding to the specified resource object. This API uses ...@@ -414,6 +394,8 @@ Obtains the string corresponding to the specified resource object. This API uses
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -447,7 +429,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -447,7 +429,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -461,6 +443,8 @@ Obtains the string corresponding to the specified resource object. This API uses ...@@ -461,6 +443,8 @@ Obtains the string corresponding to the specified resource object. This API uses
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -497,7 +481,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -497,7 +481,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringValue promise error is " + error); console.log("getStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -538,7 +522,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -538,7 +522,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -582,7 +566,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -582,7 +566,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringArrayValue promise error is " + error); console.log("getStringArrayValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -594,6 +578,8 @@ Obtains the string array corresponding to the specified resource object. This AP ...@@ -594,6 +578,8 @@ Obtains the string array corresponding to the specified resource object. This AP
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -627,7 +613,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -627,7 +613,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -639,6 +625,8 @@ Obtains the string array corresponding to the specified resource object. This AP ...@@ -639,6 +625,8 @@ Obtains the string array corresponding to the specified resource object. This AP
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -675,7 +663,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -675,7 +663,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringArray promise error is " + error); console.log("getStringArray promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getStringArrayValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -714,7 +702,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -714,7 +702,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -754,7 +742,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -754,7 +742,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -796,7 +784,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -796,7 +784,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaContent promise error is " + error); console.log("getMediaContent promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -839,7 +827,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -839,7 +827,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -851,6 +839,8 @@ Obtains the content of the media file corresponding to the specified resource ob ...@@ -851,6 +839,8 @@ Obtains the content of the media file corresponding to the specified resource ob
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -883,7 +873,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -883,7 +873,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -895,6 +885,8 @@ Obtains the content of the media file with the screen density corresponding to t ...@@ -895,6 +885,8 @@ Obtains the content of the media file with the screen density corresponding to t
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -928,7 +920,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -928,7 +920,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -940,6 +932,8 @@ Obtains the content of the media file corresponding to the specified resource ob ...@@ -940,6 +932,8 @@ Obtains the content of the media file corresponding to the specified resource ob
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -975,7 +969,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -975,7 +969,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaContent promise error is " + error); console.log("getMediaContent promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -987,6 +981,8 @@ Obtains the content of the media file with the screen density corresponding to t ...@@ -987,6 +981,8 @@ Obtains the content of the media file with the screen density corresponding to t
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1023,7 +1019,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1023,7 +1019,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1062,7 +1058,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1062,7 +1058,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1102,7 +1098,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1102,7 +1098,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1144,7 +1140,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1144,7 +1140,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaContentBase64 promise error is " + error); console.log("getMediaContentBase64 promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1187,7 +1183,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1187,7 +1183,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1199,6 +1195,8 @@ Obtains the Base64 code of the image corresponding to the specified resource obj ...@@ -1199,6 +1195,8 @@ Obtains the Base64 code of the image corresponding to the specified resource obj
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1231,7 +1229,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1231,7 +1229,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1243,6 +1241,8 @@ Obtains the Base64 code of an image with the screen density corresponding to the ...@@ -1243,6 +1241,8 @@ Obtains the Base64 code of an image with the screen density corresponding to the
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1270,13 +1270,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1270,13 +1270,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => { this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => {
if (error != null) { if (error != null) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} else { } else {
let media = value; let media = value;
} }
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1288,6 +1288,8 @@ Obtains the Base64 code of the image corresponding to the specified resource obj ...@@ -1288,6 +1288,8 @@ Obtains the Base64 code of the image corresponding to the specified resource obj
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1323,7 +1325,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1323,7 +1325,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaContentBase64 promise error is " + error); console.log("getMediaContentBase64 promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1335,6 +1337,8 @@ Obtains the Base64 code of an image with the screen density corresponding to the ...@@ -1335,6 +1337,8 @@ Obtains the Base64 code of an image with the screen density corresponding to the
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1371,7 +1375,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1371,7 +1375,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1391,16 +1395,18 @@ Obtains the device configuration. This API uses an asynchronous callback to retu ...@@ -1391,16 +1395,18 @@ Obtains the device configuration. This API uses an asynchronous callback to retu
**Example** **Example**
```ts ```ts
resourceManager.getResourceManager((error, mgr) => { try {
mgr.getConfiguration((error, value) => { this.context.resourceManager.getConfiguration((error, value) => {
if (error != null) { if (error != null) {
console.log("error is " + error); console.error("getConfiguration callback error is " + error);
} else { } else {
let direction = value.direction; let direction = value.direction;
let locale = value.locale; let locale = value.locale;
} }
}); });
}); } catch (error) {
console.error("getConfiguration callback error is " + error);
}
``` ```
...@@ -1420,14 +1426,16 @@ Obtains the device configuration. This API uses a promise to return the result. ...@@ -1420,14 +1426,16 @@ Obtains the device configuration. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
resourceManager.getResourceManager((error, mgr) => { try {
mgr.getConfiguration().then(value => { this.context.resourceManager.getConfiguration().then(value => {
let direction = value.direction; let direction = value.direction;
let locale = value.locale; let locale = value.locale;
}).catch(error => { }).catch(error => {
console.log("getConfiguration promise error is " + error); console.error("getConfiguration promise error is " + error);
}); });
}); } catch (error) {
console.error("getConfiguration promise error is " + error);
}
``` ```
...@@ -1447,16 +1455,18 @@ Obtains the device capability. This API uses an asynchronous callback to return ...@@ -1447,16 +1455,18 @@ Obtains the device capability. This API uses an asynchronous callback to return
**Example** **Example**
```ts ```ts
resourceManager.getResourceManager((error, mgr) => { try {
mgr.getDeviceCapability((error, value) => { this.context.resourceManager.getDeviceCapability((error, value) => {
if (error != null) { if (error != null) {
console.log("error is " + error); console.error("getDeviceCapability callback error is " + error);
} else { } else {
let screenDensity = value.screenDensity; let screenDensity = value.screenDensity;
let deviceType = value.deviceType; let deviceType = value.deviceType;
} }
}); });
}); } catch (error) {
console.error("getDeviceCapability callback error is " + error);
}
``` ```
...@@ -1476,17 +1486,18 @@ Obtains the device capability. This API uses a promise to return the result. ...@@ -1476,17 +1486,18 @@ Obtains the device capability. This API uses a promise to return the result.
**Example** **Example**
```ts ```ts
resourceManager.getResourceManager((error, mgr) => { try {
mgr.getDeviceCapability().then(value => { this.context.resourceManager.getDeviceCapability().then(value => {
let screenDensity = value.screenDensity; let screenDensity = value.screenDensity;
let deviceType = value.deviceType; let deviceType = value.deviceType;
}).catch(error => { }).catch(error => {
console.log("getDeviceCapability promise error is " + error); console.error("getDeviceCapability promise error is " + error);
}); });
}); } catch (error) {
console.error("getDeviceCapability promise error is " + error);
}
``` ```
### getPluralStringValue<sup>9+</sup> ### getPluralStringValue<sup>9+</sup>
getPluralStringValue(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void getPluralStringValue(resId: number, num: number, callback: AsyncCallback&lt;string&gt;): void
...@@ -1524,8 +1535,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1524,8 +1535,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1569,8 +1580,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1569,8 +1580,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getPluralStringValue promise error is " + error); console.log("getPluralStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
### getPluralStringValue<sup>9+</sup> ### getPluralStringValue<sup>9+</sup>
...@@ -1581,6 +1592,8 @@ Obtains the singular-plural string corresponding to the specified resource objec ...@@ -1581,6 +1592,8 @@ Obtains the singular-plural string corresponding to the specified resource objec
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1615,9 +1628,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1615,9 +1628,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
### getPluralStringValue<sup>9+</sup> ### getPluralStringValue<sup>9+</sup>
...@@ -1628,6 +1640,8 @@ Obtains the singular-plural string corresponding to the specified resource objec ...@@ -1628,6 +1640,8 @@ Obtains the singular-plural string corresponding to the specified resource objec
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -1665,7 +1679,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1665,7 +1679,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getPluralStringValue promise error is " + error); console.log("getPluralStringValue promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`callback getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getPluralStringValue failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1704,9 +1718,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1704,9 +1718,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
### getRawFileContent<sup>9+</sup> ### getRawFileContent<sup>9+</sup>
...@@ -1746,7 +1759,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1746,7 +1759,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getRawFileContent promise error is " + error); console.log("getRawFileContent promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getRawFileContent failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1787,8 +1800,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1787,8 +1800,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
}; }
``` ```
### getRawFd<sup>9+</sup> ### getRawFd<sup>9+</sup>
...@@ -1831,7 +1844,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1831,7 +1844,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
}); });
} catch (error) { } catch (error) {
console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`);
}; }
``` ```
### getRawFileList<sup>10+</sup> ### getRawFileList<sup>10+</sup>
...@@ -1862,15 +1875,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1862,15 +1875,14 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { // Passing "" means to obtain the list of files in the root directory of the raw file. try { // Passing "" means to obtain the list of files in the root directory of the raw file.
this.context.resourceManager.getRawFileList("", (error, value) => { this.context.resourceManager.getRawFileList("", (error, value) => {
if (error != null) { if (error != null) {
console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
} else { } else {
let rawFile = value; let rawFile = value;
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
### getRawFileList<sup>10+</sup> ### getRawFileList<sup>10+</sup>
...@@ -1907,71 +1919,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -1907,71 +1919,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
this.context.resourceManager.getRawFileList("").then(value => { this.context.resourceManager.getRawFileList("").then(value => {
let rawFile = value; let rawFile = value;
}).catch(error => { }).catch(error => {
console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
### closeRawFileDescriptor<sup>8+</sup>
closeRawFileDescriptor(path: string, callback: AsyncCallback&lt;void&gt;): void
Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ----------- |
| path | string | Yes | Path of the raw file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example**
```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.closeRawFileDescriptor("test.xml", (error, value) => {
if (error != null) {
console.log("error is " + error);
}
});
});
```
### closeRawFileDescriptor<sup>8+</sup>
closeRawFileDescriptor(path: string): Promise&lt;void&gt;
Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Path of the raw file.|
**Return value**
| Type | Description |
| ------------------- | ---- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.closeRawFileDescriptor("test.xml").then(value => {
let result = value;
}).catch(error => {
console.log("closeRawFileDescriptor promise error is " + error);
});
});
```
### closeRawFd<sup>9+</sup> ### closeRawFd<sup>9+</sup>
closeRawFd(path: string, callback: AsyncCallback&lt;void&gt;): void closeRawFd(path: string, callback: AsyncCallback&lt;void&gt;): void
...@@ -2004,7 +1958,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2004,7 +1958,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback closeRawFd failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback closeRawFd failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2046,7 +2000,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2046,7 +2000,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("closeRawFd promise error is " + error); console.log("closeRawFd promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise closeRawFd failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise closeRawFd failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2060,9 +2014,11 @@ Releases a created **resourceManager** object. ...@@ -2060,9 +2014,11 @@ Releases a created **resourceManager** object.
**Example** **Example**
```ts ```ts
resourceManager.getResourceManager((error, mgr) => { try {
mgr.release(); this.context.resourceManager.release();
}); } catch (error) {
console.error("release error is " + error);
}
``` ```
### getStringByName<sup>9+</sup> ### getStringByName<sup>9+</sup>
...@@ -2101,9 +2057,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2101,9 +2057,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getStringByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
### getStringByName<sup>9+</sup> ### getStringByName<sup>9+</sup>
...@@ -2145,7 +2100,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2145,7 +2100,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringByName promise error is " + error); console.log("getStringByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getStringByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2185,7 +2140,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2185,7 +2140,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2228,7 +2183,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2228,7 +2183,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getStringArrayByName promise error is " + error); console.log("getStringArrayByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getStringArrayByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2267,7 +2222,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2267,7 +2222,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2307,7 +2262,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2307,7 +2262,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2392,7 +2347,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2392,7 +2347,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2431,7 +2386,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2431,7 +2386,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2471,7 +2426,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2471,7 +2426,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2513,7 +2468,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2513,7 +2468,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getMediaBase64ByName promise error is " + error); console.log("getMediaBase64ByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2556,7 +2511,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2556,7 +2511,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
}); });
} catch (error) { } catch (error) {
console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2597,7 +2552,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2597,7 +2552,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2642,7 +2597,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2642,7 +2597,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getPluralStringByName promise error is " + error); console.log("getPluralStringByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getPluralStringByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2681,7 +2636,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2681,7 +2636,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringSync($r('app.string.test').id); this.context.resourceManager.getStringSync($r('app.string.test').id);
} catch (error) { } catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2722,7 +2677,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2722,7 +2677,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78); this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78);
} catch (error) { } catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2734,6 +2689,8 @@ Obtains the string corresponding to the specified resource object. This API retu ...@@ -2734,6 +2689,8 @@ Obtains the string corresponding to the specified resource object. This API retu
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -2766,7 +2723,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2766,7 +2723,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringSync(resource); this.context.resourceManager.getStringSync(resource);
} catch (error) { } catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2778,6 +2735,8 @@ Obtains the string corresponding to the specified resource object and formats th ...@@ -2778,6 +2735,8 @@ Obtains the string corresponding to the specified resource object and formats th
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -2812,7 +2771,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2812,7 +2771,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78); this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78);
} catch (error) { } catch (error) {
console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getStringSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2851,7 +2810,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2851,7 +2810,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringByNameSync("test"); this.context.resourceManager.getStringByNameSync("test");
} catch (error) { } catch (error) {
console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2892,7 +2851,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2892,7 +2851,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78); this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78);
} catch (error) { } catch (error) {
console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getStringByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -2931,7 +2890,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2931,7 +2890,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id); this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id);
} catch (error) { } catch (error) {
console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
### getBoolean<sup>9+</sup> ### getBoolean<sup>9+</sup>
...@@ -2942,6 +2901,8 @@ Obtains the Boolean result corresponding to the specified resource object. This ...@@ -2942,6 +2901,8 @@ Obtains the Boolean result corresponding to the specified resource object. This
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -2974,7 +2935,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -2974,7 +2935,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getBoolean(resource); this.context.resourceManager.getBoolean(resource);
} catch (error) { } catch (error) {
console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3013,7 +2974,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3013,7 +2974,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getBooleanByName("boolean_test"); this.context.resourceManager.getBooleanByName("boolean_test");
} catch (error) { } catch (error) {
console.error(`getBooleanByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getBooleanByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3052,13 +3013,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3052,13 +3013,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value. this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value.
} catch (error) { } catch (error) {
console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`);
} }
try { try {
this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value. this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value.
} catch (error) { } catch (error) {
console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3070,6 +3031,8 @@ Obtains the integer or float value corresponding to the specified resource objec ...@@ -3070,6 +3031,8 @@ Obtains the integer or float value corresponding to the specified resource objec
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -3102,7 +3065,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3102,7 +3065,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getNumber(resource);// integer refers to the original value; float refers to the actual pixel value. this.context.resourceManager.getNumber(resource);// integer refers to the original value; float refers to the actual pixel value.
} catch (error) { } catch (error) {
console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getNumber failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3141,13 +3104,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3141,13 +3104,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getNumberByName("integer_test"); this.context.resourceManager.getNumberByName("integer_test");
} catch (error) { } catch (error) {
console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
try { try {
this.context.resourceManager.getNumberByName("float_test"); this.context.resourceManager.getNumberByName("float_test");
} catch (error) { } catch (error) {
console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getNumberByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3186,12 +3149,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3186,12 +3149,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`);
} }
try { try {
this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3203,6 +3166,8 @@ Obtains the **DrawableDescriptor** object corresponding to the specified resourc ...@@ -3203,6 +3166,8 @@ Obtains the **DrawableDescriptor** object corresponding to the specified resourc
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -3235,12 +3200,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3235,12 +3200,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getDrawableDescriptor(resource); this.context.resourceManager.getDrawableDescriptor(resource);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`);
} }
try { try {
this.context.resourceManager.getDrawableDescriptor(resource, 120); this.context.resourceManager.getDrawableDescriptor(resource, 120);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3279,12 +3244,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3279,12 +3244,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getDrawableDescriptorByName('icon'); this.context.resourceManager.getDrawableDescriptorByName('icon');
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
try { try {
this.context.resourceManager.getDrawableDescriptorByName('icon', 120); this.context.resourceManager.getDrawableDescriptorByName('icon', 120);
} catch (error) { } catch (error) {
console.error(`getDrawableDescriptor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getDrawableDescriptorByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3324,7 +3289,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3324,7 +3289,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3367,7 +3332,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3367,7 +3332,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getColor promise error is " + error); console.log("getColor promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3379,6 +3344,8 @@ Obtains the color value corresponding to the specified resource object. This API ...@@ -3379,6 +3344,8 @@ Obtains the color value corresponding to the specified resource object. This API
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -3412,7 +3379,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3412,7 +3379,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3424,6 +3391,8 @@ Obtains the color value corresponding to the specified resource object. This API ...@@ -3424,6 +3391,8 @@ Obtains the color value corresponding to the specified resource object. This API
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -3460,7 +3429,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3460,7 +3429,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getColor promise error is " + error); console.log("getColor promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3500,7 +3469,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3500,7 +3469,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
} }
}); });
} catch (error) { } catch (error) {
console.error(`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3543,7 +3512,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3543,7 +3512,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
console.log("getColorByName promise error is " + error); console.log("getColorByName promise error is " + error);
}); });
} catch (error) { } catch (error) {
console.error(`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`) console.error(`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3551,7 +3520,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3551,7 +3520,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
getColorSync(resId: number) : number; getColorSync(resId: number) : number;
Obtains the color value corresponding to the specified resource ID. The API returns the result synchronously. Obtains the color value corresponding to the specified resource ID. This API returns the result synchronously.
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
...@@ -3582,7 +3551,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3582,7 +3551,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getColorSync($r('app.color.test').id); this.context.resourceManager.getColorSync($r('app.color.test').id);
} catch (error) { } catch (error) {
console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3590,10 +3559,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3590,10 +3559,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
getColorSync(resource: Resource): number getColorSync(resource: Resource): number
Obtains the color value corresponding to the specified resource object. The API returns the result synchronously. Obtains the color value corresponding to the specified resource object. This API returns the result synchronously.
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
**Model restriction**: This API can be used only in the stage model.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -3626,7 +3597,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3626,7 +3597,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getColorSync(resource); this.context.resourceManager.getColorSync(resource);
} catch (error) { } catch (error) {
console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3634,7 +3605,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3634,7 +3605,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
getColorByNameSync(resName: string) : number; getColorByNameSync(resName: string) : number;
Obtains the color value corresponding to the specified resource name. The API returns the result synchronously. Obtains the color value corresponding to the specified resource name. This API returns the result synchronously.
**System capability**: SystemCapability.Global.ResourceManager **System capability**: SystemCapability.Global.ResourceManager
...@@ -3665,7 +3636,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3665,7 +3636,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.getColorByNameSync("test"); this.context.resourceManager.getColorByNameSync("test");
} catch (error) { } catch (error) {
console.error(`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`) console.error(`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -3697,8 +3668,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3697,8 +3668,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.context.resourceManager.addResource(path); this.context.resourceManager.addResource(path);
} catch (error) { } catch (error) {
console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`) console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
### removeResource<sup>10+</sup> ### removeResource<sup>10+</sup>
...@@ -3729,7 +3700,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco ...@@ -3729,7 +3700,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco
try { try {
this.resmgr.removeResource(path); this.resmgr.removeResource(path);
} catch (error) { } catch (error) {
console.error(`removeResource failed, error code: ${error.code}, message: ${error.message}.`) console.error(`removeResource failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -4191,3 +4162,64 @@ This API is deprecated since API version 9. You are advised to use [getRawFd](#g ...@@ -4191,3 +4162,64 @@ This API is deprecated since API version 9. You are advised to use [getRawFd](#g
}); });
}); });
``` ```
### closeRawFileDescriptor<sup>(deprecated)</sup>
closeRawFileDescriptor(path: string, callback: AsyncCallback&lt;void&gt;): void
Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses an asynchronous callback to return the result.
This API is deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9).
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------------------------- | ---- | ----------- |
| path | string | Yes | Path of the raw file.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result. |
**Example**
```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.closeRawFileDescriptor("test.xml", (error, value) => {
if (error != null) {
console.log("error is " + error);
}
});
});
```
### closeRawFileDescriptor<sup>(deprecated)</sup>
closeRawFileDescriptor(path: string): Promise&lt;void&gt;
Closes the descriptor of the raw file in the **resources/rawfile** directory. This API uses a promise to return the result.
This API is deprecated since API version 9. You are advised to use [closeRawFd](#closerawfd9-1).
**System capability**: SystemCapability.Global.ResourceManager
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------- |
| path | string | Yes | Path of the raw file.|
**Return value**
| Type | Description |
| ------------------- | ---- |
| Promise&lt;void&gt; | Promise that returns no value.|
**Example**
```ts
resourceManager.getResourceManager((error, mgr) => {
mgr.closeRawFileDescriptor("test.xml").then(value => {
let result = value;
}).catch(error => {
console.log("closeRawFileDescriptor promise error is " + error);
});
});
```
...@@ -16,7 +16,7 @@ import runningLock from '@ohos.runningLock'; ...@@ -16,7 +16,7 @@ import runningLock from '@ohos.runningLock';
isSupported(type: RunningLockType): boolean; isSupported(type: RunningLockType): boolean;
Checks whether the specified type of **RunningLock** is supported. This API uses an asynchronous callback to return the result. Checks whether the specified type of **RunningLock** is supported.
**System capability:** SystemCapability.PowerManager.PowerManager.Core **System capability:** SystemCapability.PowerManager.PowerManager.Core
...@@ -26,7 +26,7 @@ Checks whether the specified type of **RunningLock** is supported. This API uses ...@@ -26,7 +26,7 @@ Checks whether the specified type of **RunningLock** is supported. This API uses
| ------ | ----------------------------------- | ---- | -------------------- | | ------ | ----------------------------------- | ---- | -------------------- |
| type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object.| | type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object.|
**Return Value** **Return value**
| Type | Description | | Type | Description |
| ------- | --------------------------------------- | | ------- | --------------------------------------- |
...@@ -69,14 +69,6 @@ Creates a **RunningLock** object. ...@@ -69,14 +69,6 @@ Creates a **RunningLock** object.
| type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object to be created. | | type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object to be created. |
| callback | AsyncCallback<[RunningLock](#runninglock)> | Yes | Callback used to return the result. If a lock is successfully created, **err** is **undefined** and **data** is the created **RunningLock**. Otherwise, **err** is an error object.| | callback | AsyncCallback<[RunningLock](#runninglock)> | Yes | Callback used to return the result. If a lock is successfully created, **err** is **undefined** and **data** is the created **RunningLock**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [RunningLock Error Codes](../errorcodes/errorcode-runninglock.md).
| ID | Error Message |
|---------|----------|
| 4900101 | If connecting to the service failed. |
**Example** **Example**
```js ```js
...@@ -106,20 +98,12 @@ Creates a **RunningLock** object. ...@@ -106,20 +98,12 @@ Creates a **RunningLock** object.
| name | string | Yes | Name of the **RunningLock** object. | | name | string | Yes | Name of the **RunningLock** object. |
| type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object to be created.| | type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object to be created.|
**Return Value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------------ | ------------------------------------ | | ------------------------------------------ | ------------------------------------ |
| Promise&lt;[RunningLock](#runninglock)&gt; | Promise used to return the result.| | Promise&lt;[RunningLock](#runninglock)&gt; | Promise used to return the result.|
**Error codes**
For details about the error codes, see [RunningLock Error Codes](../errorcodes/errorcode-runninglock.md).
| ID | Error Message |
|---------|----------|
| 4900101 | If connecting to the service failed. |
**Example** **Example**
```js ```js
...@@ -138,7 +122,7 @@ isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback&lt;boo ...@@ -138,7 +122,7 @@ isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback&lt;boo
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [runningLock.isSupported](#runninglockissupported9). > **NOTE**<br>This API is deprecated since API version 9. You are advised to use [runningLock.isSupported](#runninglockissupported9).
Checks whether the specified type of **RunningLock** is supported. This API uses an asynchronous callback to return the result. This API uses an asynchronous callback to return the result. Checks whether the specified type of **RunningLock** is supported. This API uses an asynchronous callback to return the result.
**System capability:** SystemCapability.PowerManager.PowerManager.Core **System capability:** SystemCapability.PowerManager.PowerManager.Core
...@@ -167,7 +151,7 @@ isRunningLockTypeSupported(type: RunningLockType): Promise&lt;boolean> ...@@ -167,7 +151,7 @@ isRunningLockTypeSupported(type: RunningLockType): Promise&lt;boolean>
> **NOTE**<br>This API is deprecated since API version 9. You are advised to use [runningLock.isSupported](#runninglockissupported9). > **NOTE**<br>This API is deprecated since API version 9. You are advised to use [runningLock.isSupported](#runninglockissupported9).
Checks whether the specified type of **RunningLock** is supported. This API uses an asynchronous callback to return the result. This API uses a promise to return the result. Checks whether the specified type of **RunningLock** is supported. This API uses a promise to return the result.
**System capability:** SystemCapability.PowerManager.PowerManager.Core **System capability:** SystemCapability.PowerManager.PowerManager.Core
...@@ -177,7 +161,7 @@ Checks whether the specified type of **RunningLock** is supported. This API uses ...@@ -177,7 +161,7 @@ Checks whether the specified type of **RunningLock** is supported. This API uses
| ------ | ----------------------------------- | ---- | -------------------- | | ------ | ----------------------------------- | ---- | -------------------- |
| type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object.| | type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object.|
**Return Value** **Return value**
| Type | Description | | Type | Description |
| ---------------------- | ---------------------------------------------------- | | ---------------------- | ---------------------------------------------------- |
...@@ -246,7 +230,7 @@ Creates a **RunningLock** object. ...@@ -246,7 +230,7 @@ Creates a **RunningLock** object.
| name | string | Yes | Name of the **RunningLock** object. | | name | string | Yes | Name of the **RunningLock** object. |
| type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object to be created.| | type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object to be created.|
**Return Value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------------ | ------------------------------------ | | ------------------------------------------ | ------------------------------------ |
...@@ -354,7 +338,7 @@ Checks the hold status of the **Runninglock** object. ...@@ -354,7 +338,7 @@ Checks the hold status of the **Runninglock** object.
**System capability:** SystemCapability.PowerManager.PowerManager.Core **System capability:** SystemCapability.PowerManager.PowerManager.Core
**Return Value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | ------------------------------------------------------------ |
...@@ -452,7 +436,7 @@ Checks the hold status of the **Runninglock** object. ...@@ -452,7 +436,7 @@ Checks the hold status of the **Runninglock** object.
**System capability:** SystemCapability.PowerManager.PowerManager.Core **System capability:** SystemCapability.PowerManager.PowerManager.Core
**Return Value** **Return value**
| Type | Description | | Type | Description |
| ------- | ------------------------------------------------------------ | | ------- | ------------------------------------------------------------ |
| boolean | The value **true** indicates that the **Runninglock** object is held; and the value **false** indicates that the **Runninglock** object is released.| | boolean | The value **true** indicates that the **Runninglock** object is held; and the value **false** indicates that the **Runninglock** object is released.|
...@@ -478,5 +462,5 @@ Enumerates the types of **RunningLock** objects. ...@@ -478,5 +462,5 @@ Enumerates the types of **RunningLock** objects.
| Name | Value | Description | | Name | Value | Description |
| --------------------------------- | ---- | ------------------------------------------------------------ | | --------------------------------- | ---- | ------------------------------------------------------------ |
| BACKGROUND<sup>(deprecated)</sup> | 1 | A lock that prevents the system from hibernating when the screen is off.<br>**NOTE**<br>This parameter is supported since API version 7 and deprecated since API version 10.| | BACKGROUND<sup>(deprecated)</sup> | 1 | A lock that prevents the system from hibernating when the screen is off.<br>**NOTE**<br/>This parameter is supported since API version 7 and deprecated since API version 10.|
| PROXIMITY_SCREEN_CONTROL | 2 | A lock that determines whether to turn on or off the screen based on the distance away from the screen. | | PROXIMITY_SCREEN_CONTROL | 2 | A lock that determines whether to turn on or off the screen based on the distance away from the screen. |
# # @ohos.net.socket (Socket Connection) # # @ohos.net.socket (Socket Connection)
The **socket** module implements data transfer over TCPSocket, UDPSocket, WebSocket, and TLSSocket connections. The **socket** module implements data transfer over TCP, UDP, Web, and TLS socket connections.
> **NOTE** > **NOTE**
> >
...@@ -34,7 +34,7 @@ let udp = socket.constructUDPSocketInstance(); ...@@ -34,7 +34,7 @@ let udp = socket.constructUDPSocketInstance();
## UDPSocket<sup>7+</sup> ## UDPSocket<sup>7+</sup>
Defines a UDPSocket connection. Before calling UDPSocket APIs, you need to call [socket.constructUDPSocketInstance](#socketconstructudpsocketinstance) to create a **UDPSocket** object. Defines a UDP socket connection. Before calling UDPSocket APIs, you need to call [socket.constructUDPSocketInstance](#socketconstructudpsocketinstance) to create a **UDPSocket** object.
### bind<sup>7+</sup> ### bind<sup>7+</sup>
...@@ -118,7 +118,7 @@ promise.then(() => { ...@@ -118,7 +118,7 @@ promise.then(() => {
send(options: UDPSendOptions, callback: AsyncCallback\<void\>): void send(options: UDPSendOptions, callback: AsyncCallback\<void\>): void
Sends data over a UDPSocket connection. This API uses an asynchronous callback to return the result. Sends data over a UDP socket connection. This API uses an asynchronous callback to return the result.
Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port. Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port.
...@@ -130,7 +130,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p ...@@ -130,7 +130,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDPSocket connection. For details, see [UDPSendOptions](#udpsendoptions).| | options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDP socket connection. For details, see [UDPSendOptions](#udpsendoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes** **Error codes**
...@@ -164,7 +164,7 @@ udp.send({ ...@@ -164,7 +164,7 @@ udp.send({
send(options: UDPSendOptions): Promise\<void\> send(options: UDPSendOptions): Promise\<void\>
Sends data over a UDPSocket connection. This API uses a promise to return the result. Sends data over a UDP socket connection. This API uses a promise to return the result.
Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port. Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port.
...@@ -176,7 +176,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p ...@@ -176,7 +176,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDPSocket connection. For details, see [UDPSendOptions](#udpsendoptions).| | options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDP socket connection. For details, see [UDPSendOptions](#udpsendoptions).|
**Error codes** **Error codes**
...@@ -214,7 +214,7 @@ promise.then(() => { ...@@ -214,7 +214,7 @@ promise.then(() => {
close(callback: AsyncCallback\<void\>): void close(callback: AsyncCallback\<void\>): void
Closes a UDPSocket connection. This API uses an asynchronous callback to return the result. Closes a UDP socket connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -243,7 +243,7 @@ udp.close(err => { ...@@ -243,7 +243,7 @@ udp.close(err => {
close(): Promise\<void\> close(): Promise\<void\>
Closes a UDPSocket connection. This API uses a promise to return the result. Closes a UDP socket connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -271,7 +271,7 @@ promise.then(() => { ...@@ -271,7 +271,7 @@ promise.then(() => {
getState(callback: AsyncCallback\<SocketStateBase\>): void getState(callback: AsyncCallback\<SocketStateBase\>): void
Obtains the status of the UDPSocket connection. This API uses an asynchronous callback to return the result. Obtains the status of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **bind** is successfully called. > This API can be called only after **bind** is successfully called.
...@@ -316,7 +316,7 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { ...@@ -316,7 +316,7 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
getState(): Promise\<SocketStateBase\> getState(): Promise\<SocketStateBase\>
Obtains the status of the UDPSocket connection. This API uses a promise to return the result. Obtains the status of the UDP socket connection. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **bind** is successfully called. > This API can be called only after **bind** is successfully called.
...@@ -355,7 +355,7 @@ promise.then(err => { ...@@ -355,7 +355,7 @@ promise.then(err => {
setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\<void\>): void setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the UDPSocket connection. This API uses an asynchronous callback to return the result. Sets other properties of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **bind** is successfully called. > This API can be called only after **bind** is successfully called.
...@@ -368,7 +368,7 @@ Sets other properties of the UDPSocket connection. This API uses an asynchronous ...@@ -368,7 +368,7 @@ Sets other properties of the UDPSocket connection. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDPSocket connection. For details, see [UDPExtraOptions](#udpextraoptions).| | options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDP socket connection. For details, see [UDPExtraOptions](#udpextraoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes** **Error codes**
...@@ -408,7 +408,7 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { ...@@ -408,7 +408,7 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
setExtraOptions(options: UDPExtraOptions): Promise\<void\> setExtraOptions(options: UDPExtraOptions): Promise\<void\>
Sets other properties of the UDPSocket connection. This API uses a promise to return the result. Sets other properties of the UDP socket connection. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **bind** is successfully called. > This API can be called only after **bind** is successfully called.
...@@ -421,7 +421,7 @@ Sets other properties of the UDPSocket connection. This API uses a promise to re ...@@ -421,7 +421,7 @@ Sets other properties of the UDPSocket connection. This API uses a promise to re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDPSocket connection. For details, see [UDPExtraOptions](#udpextraoptions).| | options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDP socket connection. For details, see [UDPExtraOptions](#udpextraoptions).|
**Return value** **Return value**
...@@ -464,7 +464,7 @@ promise.then(() => { ...@@ -464,7 +464,7 @@ promise.then(() => {
on(type: 'message', callback: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void on(type: 'message', callback: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for message receiving events of the UDPSocket connection. This API uses an asynchronous callback to return the result. Subscribes to **message** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -495,10 +495,10 @@ udp.on('message', value => { ...@@ -495,10 +495,10 @@ udp.on('message', value => {
off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for message receiving events of the UDPSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from **message** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -524,7 +524,7 @@ let callback = value => { ...@@ -524,7 +524,7 @@ let callback = value => {
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
} }
udp.on('message', callback); udp.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
udp.off('message', callback); udp.off('message', callback);
udp.off('message'); udp.off('message');
``` ```
...@@ -533,7 +533,7 @@ udp.off('message'); ...@@ -533,7 +533,7 @@ udp.off('message');
on(type: 'listening' | 'close', callback: Callback\<void\>): void on(type: 'listening' | 'close', callback: Callback\<void\>): void
Enables listening for data packet message events or close events of the UDPSocket connection. This API uses an asynchronous callback to return the result. Subscribes to **listening** events or **close** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -560,10 +560,10 @@ udp.on('close', () => { ...@@ -560,10 +560,10 @@ udp.on('close', () => {
off(type: 'listening' | 'close', callback?: Callback\<void\>): void off(type: 'listening' | 'close', callback?: Callback\<void\>): void
Disables listening for data packet message events or close events of the UDPSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from **listening** events or **close** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -582,14 +582,14 @@ let callback1 = () => { ...@@ -582,14 +582,14 @@ let callback1 = () => {
console.log("on listening, success"); console.log("on listening, success");
} }
udp.on('listening', callback1); udp.on('listening', callback1);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
udp.off('listening', callback1); udp.off('listening', callback1);
udp.off('listening'); udp.off('listening');
let callback2 = () => { let callback2 = () => {
console.log("on close, success"); console.log("on close, success");
} }
udp.on('close', callback2); udp.on('close', callback2);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
udp.off('close', callback2); udp.off('close', callback2);
udp.off('close'); udp.off('close');
``` ```
...@@ -598,7 +598,7 @@ udp.off('close'); ...@@ -598,7 +598,7 @@ udp.off('close');
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the UDPSocket connection. This API uses an asynchronous callback to return the result. Subscribes to **error** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -622,10 +622,10 @@ udp.on('error', err => { ...@@ -622,10 +622,10 @@ udp.on('error', err => {
off(type: 'error', callback?: ErrorCallback): void off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the UDPSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from **error** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -644,7 +644,7 @@ let callback = err => { ...@@ -644,7 +644,7 @@ let callback = err => {
console.log("on error, err:" + JSON.stringify(err)); console.log("on error, err:" + JSON.stringify(err));
} }
udp.on('error', callback); udp.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
udp.off('error', callback); udp.off('error', callback);
udp.off('error'); udp.off('error');
``` ```
...@@ -663,7 +663,7 @@ Defines the destination address. ...@@ -663,7 +663,7 @@ Defines the destination address.
## UDPSendOptions<sup>7+</sup> ## UDPSendOptions<sup>7+</sup>
Defines the parameters for sending data over the UDPSocket connection. Defines the parameters for sending data over the UDP socket connection.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -674,7 +674,7 @@ Defines the parameters for sending data over the UDPSocket connection. ...@@ -674,7 +674,7 @@ Defines the parameters for sending data over the UDPSocket connection.
## UDPExtraOptions<sup>7+</sup> ## UDPExtraOptions<sup>7+</sup>
Defines other properties of the UDPSocket connection. Defines other properties of the UDP socket connection.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -684,7 +684,7 @@ Defines other properties of the UDPSocket connection. ...@@ -684,7 +684,7 @@ Defines other properties of the UDPSocket connection.
| receiveBufferSize | number | No | Size of the receive buffer, in bytes. The default value is **0**. | | receiveBufferSize | number | No | Size of the receive buffer, in bytes. The default value is **0**. |
| sendBufferSize | number | No | Size of the send buffer, in bytes. The default value is **0**. | | sendBufferSize | number | No | Size of the send buffer, in bytes. The default value is **0**. |
| reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. | | reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. |
| socketTimeout | number | No | Timeout duration of the UDPSocket connection, in ms. The default value is **0**.| | socketTimeout | number | No | Timeout duration of the UDP socket connection, in ms. The default value is **0**.|
## SocketStateBase<sup>7+</sup> ## SocketStateBase<sup>7+</sup>
...@@ -739,7 +739,7 @@ let tcp = socket.constructTCPSocketInstance(); ...@@ -739,7 +739,7 @@ let tcp = socket.constructTCPSocketInstance();
## TCPSocket<sup>7+</sup> ## TCPSocket<sup>7+</sup>
Defines a TCPSocket connection. Before calling TCPSocket APIs, you need to call [socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance) to create a **TCPSocket** object. Defines a TCP socket connection. Before calling TCPSocket APIs, you need to call [socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance) to create a **TCPSocket** object.
### bind<sup>7+</sup> ### bind<sup>7+</sup>
...@@ -747,6 +747,9 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void ...@@ -747,6 +747,9 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. This API uses an asynchronous callback to return the result. Binds the IP address and port number. The port number can be specified or randomly allocated by the system. This API uses an asynchronous callback to return the result.
> **NOTE**
> If the operation fails, the system randomly allocates a port number.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -784,6 +787,9 @@ bind(address: NetAddress): Promise\<void\> ...@@ -784,6 +787,9 @@ bind(address: NetAddress): Promise\<void\>
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. This API uses a promise to return the result. Binds the IP address and port number. The port number can be specified or randomly allocated by the system. This API uses a promise to return the result.
> **NOTE**
> If the operation fails, the system randomly allocates a port number.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -836,7 +842,7 @@ Sets up a connection to the specified IP address and port number. This API uses ...@@ -836,7 +842,7 @@ Sets up a connection to the specified IP address and port number. This API uses
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCPSocket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).| | options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCP socket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes** **Error codes**
...@@ -873,7 +879,7 @@ Sets up a connection to the specified IP address and port number. This API uses ...@@ -873,7 +879,7 @@ Sets up a connection to the specified IP address and port number. This API uses
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCPSocket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).| | options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCP socket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).|
**Return value** **Return value**
...@@ -904,7 +910,7 @@ promise.then(() => { ...@@ -904,7 +910,7 @@ promise.then(() => {
send(options: TCPSendOptions, callback: AsyncCallback\<void\>): void send(options: TCPSendOptions, callback: AsyncCallback\<void\>): void
Sends data over a TCPSocket connection. This API uses an asynchronous callback to return the result. Sends data over a TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **connect** is successfully called. > This API can be called only after **connect** is successfully called.
...@@ -917,7 +923,7 @@ Sends data over a TCPSocket connection. This API uses an asynchronous callback t ...@@ -917,7 +923,7 @@ Sends data over a TCPSocket connection. This API uses an asynchronous callback t
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCPSocket connection. For details, see [TCPSendOptions](#tcpsendoptions).| | options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCP socket connection. For details, see [TCPSendOptions](#tcpsendoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes** **Error codes**
...@@ -950,7 +956,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim ...@@ -950,7 +956,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim
send(options: TCPSendOptions): Promise\<void\> send(options: TCPSendOptions): Promise\<void\>
Sends data over a TCPSocket connection. This API uses a promise to return the result. Sends data over a TCP socket connection. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **connect** is successfully called. > This API can be called only after **connect** is successfully called.
...@@ -963,7 +969,7 @@ Sends data over a TCPSocket connection. This API uses a promise to return the re ...@@ -963,7 +969,7 @@ Sends data over a TCPSocket connection. This API uses a promise to return the re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCPSocket connection. For details, see [TCPSendOptions](#tcpsendoptions).| | options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCP socket connection. For details, see [TCPSendOptions](#tcpsendoptions).|
**Return value** **Return value**
...@@ -1002,7 +1008,7 @@ promise1.then(() => { ...@@ -1002,7 +1008,7 @@ promise1.then(() => {
close(callback: AsyncCallback\<void\>): void close(callback: AsyncCallback\<void\>): void
Closes a TCPSocket connection. This API uses an asynchronous callback to return the result. Closes a TCP socket connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -1037,7 +1043,7 @@ tcp.close(err => { ...@@ -1037,7 +1043,7 @@ tcp.close(err => {
close(): Promise\<void\> close(): Promise\<void\>
Closes a TCPSocket connection. This API uses a promise to return the result. Closes a TCP socket connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -1155,7 +1161,7 @@ promise1.then(() => { ...@@ -1155,7 +1161,7 @@ promise1.then(() => {
getState(callback: AsyncCallback\<SocketStateBase\>): void getState(callback: AsyncCallback\<SocketStateBase\>): void
Obtains the status of the TCPSocket connection. This API uses an asynchronous callback to return the result. Obtains the status of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **bind** or **connect** is successfully called. > This API can be called only after **bind** or **connect** is successfully called.
...@@ -1196,7 +1202,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa ...@@ -1196,7 +1202,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa
getState(): Promise\<SocketStateBase\> getState(): Promise\<SocketStateBase\>
Obtains the status of the TCPSocket connection. This API uses a promise to return the result. Obtains the status of the TCP socket connection. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **bind** or **connect** is successfully called. > This API can be called only after **bind** or **connect** is successfully called.
...@@ -1235,11 +1241,92 @@ promise.then(() => { ...@@ -1235,11 +1241,92 @@ promise.then(() => {
}); });
``` ```
### getSocketFd<sup>10+</sup>
getSocketFd(callback: AsyncCallback\<number\>): void
Obtains the file descriptor of the **TCPSocket** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **bind** or **connect** is successfully called.
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------ | ---- | ---------- |
| callback | AsyncCallback\<number\> | Yes | Callback used to return the result. If the operation is successful, the file descriptor of the socket is returned. Otherwise, **undefined** is returned.|
**Example**
```js
import socket from "@ohos.net.socket";
var tcp = socket.constructTCPSocketInstance();
let tunnelfd = 0
tcp.bind({
address: "0.0.0.0",
family: 1,
})
let connectAddress = {
address: "192.168.1.11",
port: 8888,
family: 1
};
tcp.connect({
address: connectAddress, timeout: 6000
})
tcp.getSocketFd((data) => {
console.info("tunenlfd: " + data);
tunnelfd = data
})
```
### getSocketFd<sup>10+</sup>
getSocketFd(): Promise\<number\>
Obtains the file descriptor of the **TCPSocket** object. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **bind** or **connect** is successfully called.
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| :----------------------------------------------- | :----------------------------------------- |
| Promise\<number\> | Promise used to return the result.|
**Example**
```js
import socket from "@ohos.net.socket";
var tcp = socket.constructTCPSocketInstance();
let tunnelfd = 0
tcp.bind({
address: "0.0.0.0",
family: 1,
})
let connectAddress = {
address: "192.168.1.11",
port: 8888,
family: 1
};
tcp.connect({
address: connectAddress, timeout: 6000
})
tcp.getSocketFd().then((data) => {
console.info("tunenlfd: " + data);
tunnelfd = data
})
```
### setExtraOptions<sup>7+</sup> ### setExtraOptions<sup>7+</sup>
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the TCPSocket connection. This API uses an asynchronous callback to return the result. Sets other properties of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **bind** or **connect** is successfully called. > This API can be called only after **bind** or **connect** is successfully called.
...@@ -1252,7 +1339,7 @@ Sets other properties of the TCPSocket connection. This API uses an asynchronous ...@@ -1252,7 +1339,7 @@ Sets other properties of the TCPSocket connection. This API uses an asynchronous
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).| | options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. | | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes** **Error codes**
...@@ -1291,7 +1378,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa ...@@ -1291,7 +1378,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa
setExtraOptions(options: TCPExtraOptions): Promise\<void\> setExtraOptions(options: TCPExtraOptions): Promise\<void\>
Sets other properties of the TCPSocket connection. This API uses a promise to return the result. Sets other properties of the TCP socket connection. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **bind** or **connect** is successfully called. > This API can be called only after **bind** or **connect** is successfully called.
...@@ -1304,7 +1391,7 @@ Sets other properties of the TCPSocket connection. This API uses a promise to re ...@@ -1304,7 +1391,7 @@ Sets other properties of the TCPSocket connection. This API uses a promise to re
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).| | options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
**Return value** **Return value**
...@@ -1350,7 +1437,7 @@ promise.then(() => { ...@@ -1350,7 +1437,7 @@ promise.then(() => {
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for message receiving events of the TCPSocket connection. This API uses an asynchronous callback to return the result. Subscribes to **message** events of the TCP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1381,10 +1468,10 @@ tcp.on('message', value => { ...@@ -1381,10 +1468,10 @@ tcp.on('message', value => {
off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for message receiving events of the TCPSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from **message** events of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1410,7 +1497,7 @@ let callback = value => { ...@@ -1410,7 +1497,7 @@ let callback = value => {
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
} }
tcp.on('message', callback); tcp.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcp.off('message', callback); tcp.off('message', callback);
tcp.off('message'); tcp.off('message');
``` ```
...@@ -1419,7 +1506,7 @@ tcp.off('message'); ...@@ -1419,7 +1506,7 @@ tcp.off('message');
on(type: 'connect' | 'close', callback: Callback\<void\>): void on(type: 'connect' | 'close', callback: Callback\<void\>): void
Enables listening for connection or close events of the TCPSocket connection. This API uses an asynchronous callback to return the result. Subscribes to connection or close events of the TCP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1446,10 +1533,10 @@ tcp.on('close', () => { ...@@ -1446,10 +1533,10 @@ tcp.on('close', () => {
off(type: 'connect' | 'close', callback?: Callback\<void\>): void off(type: 'connect' | 'close', callback?: Callback\<void\>): void
Disables listening for connection or close events of the TCPSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from connection or close events of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1468,14 +1555,14 @@ let callback1 = () => { ...@@ -1468,14 +1555,14 @@ let callback1 = () => {
console.log("on connect success"); console.log("on connect success");
} }
tcp.on('connect', callback1); tcp.on('connect', callback1);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcp.off('connect', callback1); tcp.off('connect', callback1);
tcp.off('connect'); tcp.off('connect');
let callback2 = () => { let callback2 = () => {
console.log("on close success"); console.log("on close success");
} }
tcp.on('close', callback2); tcp.on('close', callback2);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcp.off('close', callback2); tcp.off('close', callback2);
tcp.off('close'); tcp.off('close');
``` ```
...@@ -1484,7 +1571,7 @@ tcp.off('close'); ...@@ -1484,7 +1571,7 @@ tcp.off('close');
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the TCPSocket connection. This API uses an asynchronous callback to return the result. Subscribes to **error** events of the TCP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1508,10 +1595,10 @@ tcp.on('error', err => { ...@@ -1508,10 +1595,10 @@ tcp.on('error', err => {
off(type: 'error', callback?: ErrorCallback): void off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the TCPSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from **error** events of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1530,25 +1617,25 @@ let callback = err => { ...@@ -1530,25 +1617,25 @@ let callback = err => {
console.log("on error, err:" + JSON.stringify(err)); console.log("on error, err:" + JSON.stringify(err));
} }
tcp.on('error', callback); tcp.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcp.off('error', callback); tcp.off('error', callback);
tcp.off('error'); tcp.off('error');
``` ```
## TCPConnectOptions<sup>7+</sup> ## TCPConnectOptions<sup>7+</sup>
Defines TCPSocket connection parameters. Defines TCP socket connection parameters.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ---------------------------------- | ---- | -------------------------- | | ------- | ---------------------------------- | ---- | -------------------------- |
| address | [NetAddress](#netaddress) | Yes | Bound IP address and port number. | | address | [NetAddress](#netaddress) | Yes | Bound IP address and port number. |
| timeout | number | No | Timeout duration of the TCPSocket connection, in ms.| | timeout | number | No | Timeout duration of the TCP socket connection, in ms.|
## TCPSendOptions<sup>7+</sup> ## TCPSendOptions<sup>7+</sup>
Defines the parameters for sending data over the TCPSocket connection. Defines the parameters for sending data over the TCP socket connection.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1559,7 +1646,7 @@ Defines the parameters for sending data over the TCPSocket connection. ...@@ -1559,7 +1646,7 @@ Defines the parameters for sending data over the TCPSocket connection.
## TCPExtraOptions<sup>7+</sup> ## TCPExtraOptions<sup>7+</sup>
Defines other properties of the TCPSocket connection. Defines other properties of the TCP socket connection.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1567,12 +1654,12 @@ Defines other properties of the TCPSocket connection. ...@@ -1567,12 +1654,12 @@ Defines other properties of the TCPSocket connection.
| ----------------- | ------- | ---- | ------------------------------------------------------------ | | ----------------- | ------- | ---- | ------------------------------------------------------------ |
| keepAlive | boolean | No | Whether to keep the connection alive. The default value is **false**. | | keepAlive | boolean | No | Whether to keep the connection alive. The default value is **false**. |
| OOBInline | boolean | No | Whether to enable OOBInline. The default value is **false**. | | OOBInline | boolean | No | Whether to enable OOBInline. The default value is **false**. |
| TCPNoDelay | boolean | No | Whether to enable no-delay on the TCPSocket connection. The default value is **false**. | | TCPNoDelay | boolean | No | Whether to enable no-delay on the TCP socket connection. The default value is **false**. |
| socketLinger | Object | Yes | Socket linger.<br>- **on**: whether to enable socket linger. The value true means to enable socket linger and false means the opposite.<br>- **linger**: linger time, in ms. The value ranges from **0** to **65535**.<br>Specify this parameter only when **on** is set to **true**.| | socketLinger | Object | Yes | Socket linger.<br>- **on**: whether to enable socket linger. The value true means to enable socket linger and false means the opposite.<br>- **linger**: linger time, in ms. The value ranges from **0** to **65535**.<br>Specify this parameter only when **on** is set to **true**.|
| receiveBufferSize | number | No | Size of the receive buffer, in bytes. The default value is **0**. | | receiveBufferSize | number | No | Size of the receive buffer, in bytes. The default value is **0**. |
| sendBufferSize | number | No | Size of the send buffer, in bytes. The default value is **0**. | | sendBufferSize | number | No | Size of the send buffer, in bytes. The default value is **0**. |
| reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. | | reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. |
| socketTimeout | number | No | Timeout duration of the UDPSocket connection, in ms. The default value is **0**. | | socketTimeout | number | No | Timeout duration of the UDP socket connection, in ms. The default value is **0**. |
## socket.constructTCPSocketServerInstance<sup>10+</sup> ## socket.constructTCPSocketServerInstance<sup>10+</sup>
...@@ -1602,10 +1689,10 @@ Defines a TCPSocketServer connection. Before calling TCPSocketServer APIs, you n ...@@ -1602,10 +1689,10 @@ Defines a TCPSocketServer connection. Before calling TCPSocketServer APIs, you n
listen(address: NetAddress, callback: AsyncCallback\<void\>): void listen(address: NetAddress, callback: AsyncCallback\<void\>): void
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCPSocket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses an asynchronous callback to return the result. Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCP socket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> The server uses this API to perform the bind, listen, and accept operations. > The server uses this API to perform the **bind**, **listen**, and **accept** operations. If the **bind** operation fails, the system randomly allocates a port number.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -1647,10 +1734,10 @@ tcpServer.listen({ address: "192.168.xx.xxx", port: xxxx, family: 1 }, err => { ...@@ -1647,10 +1734,10 @@ tcpServer.listen({ address: "192.168.xx.xxx", port: xxxx, family: 1 }, err => {
listen(address: NetAddress): Promise\<void\> listen(address: NetAddress): Promise\<void\>
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCPSocket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses a promise to return the result. Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCP socket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> The server uses this API to perform the bind, listen, and accept operations. > The server uses this API to perform the **bind**, **listen**, and **accept** operations. If the **bind** operation fails, the system randomly allocates a port number.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -1908,7 +1995,10 @@ promise.then(() => { ...@@ -1908,7 +1995,10 @@ promise.then(() => {
on(type: 'connect', callback: Callback\<TCPSocketConnection\>): void on(type: 'connect', callback: Callback\<TCPSocketConnection\>): void
Enables listening for TCPSocketServer connection events. This API uses an asynchronous callback to return the result. Subscribes to TCPSocketServer connection events. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1938,10 +2028,10 @@ tcpServer.on('connect', function(data) { ...@@ -1938,10 +2028,10 @@ tcpServer.on('connect', function(data) {
off(type: 'connect', callback?: Callback\<TCPSocketConnection\>): void off(type: 'connect', callback?: Callback\<TCPSocketConnection\>): void
Disables listening for TCPSocketServer connection events. This API uses an asynchronous callback to return the result. Unsubscribes from TCPSocketServer connection events. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -1966,7 +2056,7 @@ let callback = data => { ...@@ -1966,7 +2056,7 @@ let callback = data => {
console.log('on connect message: ' + JSON.stringify(data)); console.log('on connect message: ' + JSON.stringify(data));
} }
tcpServer.on('connect', callback); tcpServer.on('connect', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcpServer.off('connect', callback); tcpServer.off('connect', callback);
tcpServer.off('connect'); tcpServer.off('connect');
``` ```
...@@ -1975,7 +2065,10 @@ tcpServer.off('connect'); ...@@ -1975,7 +2065,10 @@ tcpServer.off('connect');
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the TCPSocketServer connection. This API uses an asynchronous callback to return the result. Subscribes to **error** events of the TCPSocketServer connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2005,10 +2098,10 @@ tcpServer.on('error', err => { ...@@ -2005,10 +2098,10 @@ tcpServer.on('error', err => {
off(type: 'error', callback?: ErrorCallback): void off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the TCPSocketServer connection. This API uses an asynchronous callback to return the result. Unsubscribes from **error** events of the TCPSocketServer connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2033,7 +2126,7 @@ let callback = err => { ...@@ -2033,7 +2126,7 @@ let callback = err => {
console.log("on error, err:" + JSON.stringify(err)); console.log("on error, err:" + JSON.stringify(err));
} }
tcpServer.on('error', callback); tcpServer.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcpServer.off('error', callback); tcpServer.off('error', callback);
tcpServer.off('error'); tcpServer.off('error');
``` ```
...@@ -2147,7 +2240,7 @@ tcpServer.on('connect', function(client) { ...@@ -2147,7 +2240,7 @@ tcpServer.on('connect', function(client) {
close(callback: AsyncCallback\<void\>): void close(callback: AsyncCallback\<void\>): void
Closes a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. Closes a TCP socket connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -2186,7 +2279,7 @@ tcpServer.on('connect', function(client) { ...@@ -2186,7 +2279,7 @@ tcpServer.on('connect', function(client) {
close(): Promise\<void\> close(): Promise\<void\>
Closes a **TCPSocketConnection** object. This API uses a promise to return the result. Closes a TCP socket connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET **Required permissions**: ohos.permission.INTERNET
...@@ -2307,7 +2400,7 @@ tcpServer.on('connect', function(client) { ...@@ -2307,7 +2400,7 @@ tcpServer.on('connect', function(client) {
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for **message** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. Subscribes to **message** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2346,10 +2439,10 @@ tcpServer.on('connect', function(client) { ...@@ -2346,10 +2439,10 @@ tcpServer.on('connect', function(client) {
off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for **message** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. Unsubscribes from **message** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2382,7 +2475,7 @@ let callback = value => { ...@@ -2382,7 +2475,7 @@ let callback = value => {
let tcpServer = socket.constructTCPSocketServerInstance(); let tcpServer = socket.constructTCPSocketServerInstance();
tcpServer.on('connect', function(client) { tcpServer.on('connect', function(client) {
client.on('message', callback); client.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('message', callback); client.off('message', callback);
client.off('message'); client.off('message');
}); });
...@@ -2392,7 +2485,7 @@ tcpServer.on('connect', function(client) { ...@@ -2392,7 +2485,7 @@ tcpServer.on('connect', function(client) {
on(type: 'close', callback: Callback\<void\>): void on(type: 'close', callback: Callback\<void\>): void
Enables listening for **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. Subscribes to **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2424,10 +2517,10 @@ tcpServer.on('connect', function(client) { ...@@ -2424,10 +2517,10 @@ tcpServer.on('connect', function(client) {
on(type: 'close', callback: Callback\<void\>): void on(type: 'close', callback: Callback\<void\>): void
Disables listening for **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. Unsubscribes from **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2453,7 +2546,7 @@ let callback = () => { ...@@ -2453,7 +2546,7 @@ let callback = () => {
let tcpServer = socket.constructTCPSocketServerInstance(); let tcpServer = socket.constructTCPSocketServerInstance();
tcpServer.on('connect', function(client) { tcpServer.on('connect', function(client) {
client.on('close', callback); client.on('close', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('close', callback); client.off('close', callback);
client.off('close'); client.off('close');
}); });
...@@ -2463,7 +2556,7 @@ tcpServer.on('connect', function(client) { ...@@ -2463,7 +2556,7 @@ tcpServer.on('connect', function(client) {
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
Enables listening for **error** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. Subscribes to **error** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2495,10 +2588,10 @@ tcpServer.on('connect', function(client) { ...@@ -2495,10 +2588,10 @@ tcpServer.on('connect', function(client) {
off(type: 'error', callback?: ErrorCallback): void off(type: 'error', callback?: ErrorCallback): void
Disables listening for **error** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result. Unsubscribes from **error** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2524,7 +2617,7 @@ let callback = err => { ...@@ -2524,7 +2617,7 @@ let callback = err => {
let tcpServer = socket.constructTCPSocketServerInstance(); let tcpServer = socket.constructTCPSocketServerInstance();
tcpServer.on('connect', function(client) { tcpServer.on('connect', function(client) {
client.on('error', callback); client.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('error', callback); client.off('error', callback);
client.off('error'); client.off('error');
}); });
...@@ -2558,7 +2651,7 @@ let tls = socket.constructTLSSocketInstance(); ...@@ -2558,7 +2651,7 @@ let tls = socket.constructTLSSocketInstance();
## TLSSocket<sup>9+</sup> ## TLSSocket<sup>9+</sup>
Defines a TLSSocket connection. Before calling TLSSocket APIs, you need to call [socket.constructTLSSocketInstance](#socketconstructtlssocketinstance9) to create a **TLSSocket** object. Defines a TLS socket connection. Before calling TLSSocket APIs, you need to call [socket.constructTLSSocketInstance](#socketconstructtlssocketinstance9) to create a **TLSSocket** object.
### bind<sup>9+</sup> ### bind<sup>9+</sup>
...@@ -2644,7 +2737,7 @@ promise.then(() => { ...@@ -2644,7 +2737,7 @@ promise.then(() => {
getState(callback: AsyncCallback\<SocketStateBase\>): void getState(callback: AsyncCallback\<SocketStateBase\>): void
Obtains the status of the TLSSocket connection. This API uses an asynchronous callback to return the result. Obtains the status of the TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2652,7 +2745,7 @@ Obtains the status of the TLSSocket connection. This API uses an asynchronous ca ...@@ -2652,7 +2745,7 @@ Obtains the status of the TLSSocket connection. This API uses an asynchronous ca
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------ | ---- | ---------- | | -------- | ------------------------------------------------------ | ---- | ---------- |
| callback | AsyncCallback\<[SocketStateBase](#socketstatebase)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLSSocket connection is returned. If the operation fails, an error message is returned.| | callback | AsyncCallback\<[SocketStateBase](#socketstatebase)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLS socket connection is returned. If the operation fails, an error message is returned.|
**Error codes** **Error codes**
...@@ -2684,7 +2777,7 @@ tls.getState((err, data) => { ...@@ -2684,7 +2777,7 @@ tls.getState((err, data) => {
getState(): Promise\<SocketStateBase\> getState(): Promise\<SocketStateBase\>
Obtains the status of the TLSSocket connection. This API uses a promise to return the result. Obtains the status of the TLS socket connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2722,7 +2815,7 @@ promise.then(() => { ...@@ -2722,7 +2815,7 @@ promise.then(() => {
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the TCPSocket connection after **bind** is successfully called. This API uses an asynchronous callback to return the result. Sets other properties of the TCP socket connection after **bind** is successfully called. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2730,8 +2823,8 @@ Sets other properties of the TCPSocket connection after **bind** is successfully ...@@ -2730,8 +2823,8 @@ Sets other properties of the TCPSocket connection after **bind** is successfully
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).| | options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, the result of setting other properties of the TCPSocket connection is returned. If the operation fails, an error message is returned.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, the result of setting other properties of the TCP socket connection is returned. If the operation fails, an error message is returned.|
**Error codes** **Error codes**
...@@ -2774,7 +2867,7 @@ tls.setExtraOptions({ ...@@ -2774,7 +2867,7 @@ tls.setExtraOptions({
setExtraOptions(options: TCPExtraOptions): Promise\<void\> setExtraOptions(options: TCPExtraOptions): Promise\<void\>
Sets other properties of the TCPSocket connection after **bind** is successfully called. This API uses a promise to return the result. Sets other properties of the TCP socket connection after **bind** is successfully called. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2782,7 +2875,7 @@ Sets other properties of the TCPSocket connection after **bind** is successfully ...@@ -2782,7 +2875,7 @@ Sets other properties of the TCPSocket connection after **bind** is successfully
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | | ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).| | options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
**Return value** **Return value**
...@@ -2829,7 +2922,7 @@ promise.then(() => { ...@@ -2829,7 +2922,7 @@ promise.then(() => {
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void; on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void;
Enables listening for **message** events of the TLSSocket connection. This API uses an asynchronous callback to return the result. Subscribes to **message** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2860,10 +2953,10 @@ tls.on('message', value => { ...@@ -2860,10 +2953,10 @@ tls.on('message', value => {
off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for **message** events of the TLSSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from **message** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2872,7 +2965,7 @@ Disables listening for **message** events of the TLSSocket connection. This API ...@@ -2872,7 +2965,7 @@ Disables listening for **message** events of the TLSSocket connection. This API
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- |
| type | string | Yes | Type of the event to subscribe to.<br/> **message**: message receiving event.| | type | string | Yes | Type of the event to subscribe to.<br/> **message**: message receiving event.|
| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result.<br/> **message**: received message.<br>**remoteInfo**: socket connection information.| | callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result.<br> **message**: received message.<br>**remoteInfo**: socket connection information.|
**Example** **Example**
...@@ -2889,14 +2982,14 @@ let callback = value => { ...@@ -2889,14 +2982,14 @@ let callback = value => {
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
} }
tls.on('message', callback); tls.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tls.off('message', callback); tls.off('message', callback);
``` ```
### on('connect' | 'close')<sup>9+</sup> ### on('connect' | 'close')<sup>9+</sup>
on(type: 'connect' | 'close', callback: Callback\<void\>): void on(type: 'connect' | 'close', callback: Callback\<void\>): void
Enables listening for **connect** or **close** events of the TLSSocket connection. This API uses an asynchronous callback to return the result. Subscribes to **connect** or **close** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2923,10 +3016,10 @@ tls.on('close', () => { ...@@ -2923,10 +3016,10 @@ tls.on('close', () => {
off(type: 'connect' | 'close', callback?: Callback\<void\>): void off(type: 'connect' | 'close', callback?: Callback\<void\>): void
Disables listening for **connect** or **close** events of the TLSSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from **connect** or **close** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2945,14 +3038,14 @@ let callback1 = () => { ...@@ -2945,14 +3038,14 @@ let callback1 = () => {
console.log("on connect success"); console.log("on connect success");
} }
tls.on('connect', callback1); tls.on('connect', callback1);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tls.off('connect', callback1); tls.off('connect', callback1);
tls.off('connect'); tls.off('connect');
let callback2 = () => { let callback2 = () => {
console.log("on close success"); console.log("on close success");
} }
tls.on('close', callback2); tls.on('close', callback2);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tls.off('close', callback2); tls.off('close', callback2);
``` ```
...@@ -2960,7 +3053,7 @@ tls.off('close', callback2); ...@@ -2960,7 +3053,7 @@ tls.off('close', callback2);
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the TLSSocket connection. This API uses an asynchronous callback to return the result. Subscribes to **error** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -2984,10 +3077,10 @@ tls.on('error', err => { ...@@ -2984,10 +3077,10 @@ tls.on('error', err => {
off(type: 'error', callback?: ErrorCallback): void off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the TLSSocket connection. This API uses an asynchronous callback to return the result. Unsubscribes from **error** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3006,7 +3099,7 @@ let callback = err => { ...@@ -3006,7 +3099,7 @@ let callback = err => {
console.log("on error, err:" + JSON.stringify(err)); console.log("on error, err:" + JSON.stringify(err));
} }
tls.on('error', callback); tls.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tls.off('error', callback); tls.off('error', callback);
``` ```
...@@ -3014,7 +3107,7 @@ tls.off('error', callback); ...@@ -3014,7 +3107,7 @@ tls.off('error', callback);
connect(options: TLSConnectOptions, callback: AsyncCallback\<void\>): void connect(options: TLSConnectOptions, callback: AsyncCallback\<void\>): void
Sets up a TLSSocket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses an asynchronous callback to return the result. Sets up a TLS socket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3022,7 +3115,7 @@ Sets up a TLSSocket connection, and creates and initializes a TLS session after ...@@ -3022,7 +3115,7 @@ Sets up a TLSSocket connection, and creates and initializes a TLS session after
| Name | Type | Mandatory| Description| | Name | Type | Mandatory| Description|
| -------- | ---------------------------------------| ----| --------------- | | -------- | ---------------------------------------| ----| --------------- |
| options | [TLSConnectOptions](#tlsconnectoptions9) | Yes | Parameters required for the TLSSocket connection.| | options | [TLSConnectOptions](#tlsconnectoptions9) | Yes | Parameters required for the TLS socket connection.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| | callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
**Error codes** **Error codes**
...@@ -3108,7 +3201,7 @@ tlsOneWay.connect(oneWayOptions, (err, data) => { ...@@ -3108,7 +3201,7 @@ tlsOneWay.connect(oneWayOptions, (err, data) => {
connect(options: TLSConnectOptions): Promise\<void\> connect(options: TLSConnectOptions): Promise\<void\>
Sets up a TLSSocket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. Both two-way and one-way authentication modes are supported. This API uses a promise to return the result. Sets up a TLS socket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. Both two-way and one-way authentication modes are supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3209,7 +3302,7 @@ tlsOneWay.connect(oneWayOptions).then(data => { ...@@ -3209,7 +3302,7 @@ tlsOneWay.connect(oneWayOptions).then(data => {
getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void
Obtains the remote address of a TLSSocket connection. This API uses an asynchronous callback to return the result. Obtains the remote address of a TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3242,7 +3335,7 @@ tls.getRemoteAddress((err, data) => { ...@@ -3242,7 +3335,7 @@ tls.getRemoteAddress((err, data) => {
getRemoteAddress(): Promise\<NetAddress\> getRemoteAddress(): Promise\<NetAddress\>
Obtains the remote address of a TLSSocket connection. This API uses a promise to return the result. Obtains the remote address of a TLS socket connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3274,7 +3367,7 @@ promise.then(() => { ...@@ -3274,7 +3367,7 @@ promise.then(() => {
getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void
Obtains the local digital certificate after a TLSSocket connection is established. This API is applicable to two-way authentication. It uses an asynchronous callback to return the result. Obtains the local digital certificate after a TLS socket connection is established. This API is applicable to two-way authentication. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3308,7 +3401,7 @@ tls.getCertificate((err, data) => { ...@@ -3308,7 +3401,7 @@ tls.getCertificate((err, data) => {
getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\> getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
Obtains the local digital certificate after a TLSSocket connection is established. This API is applicable to two-way authentication. It uses a promise to return the result. Obtains the local digital certificate after a TLS socket connection is established. This API is applicable to two-way authentication. It uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3340,7 +3433,7 @@ tls.getCertificate().then(data => { ...@@ -3340,7 +3433,7 @@ tls.getCertificate().then(data => {
getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void
Obtains the digital certificate of the server after a TLSSocket connection is established. This API uses an asynchronous callback to return the result. Obtains the digital certificate of the server after a TLS socket connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3373,7 +3466,7 @@ tls.getRemoteCertificate((err, data) => { ...@@ -3373,7 +3466,7 @@ tls.getRemoteCertificate((err, data) => {
getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\> getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
Obtains the digital certificate of the server after a TLSSocket connection is established. This API uses a promise to return the result. Obtains the digital certificate of the server after a TLS socket connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3404,7 +3497,7 @@ tls.getRemoteCertificate().then(data => { ...@@ -3404,7 +3497,7 @@ tls.getRemoteCertificate().then(data => {
getProtocol(callback: AsyncCallback\<string\>): void getProtocol(callback: AsyncCallback\<string\>): void
Obtains the communication protocol version after a TLSSocket connection is established. This API uses an asynchronous callback to return the result. Obtains the communication protocol version after a TLS socket connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3438,7 +3531,7 @@ tls.getProtocol((err, data) => { ...@@ -3438,7 +3531,7 @@ tls.getProtocol((err, data) => {
getProtocol():Promise\<string\> getProtocol():Promise\<string\>
Obtains the communication protocol version after a TLSSocket connection is established. This API uses a promise to return the result. Obtains the communication protocol version after a TLS socket connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3470,7 +3563,7 @@ tls.getProtocol().then(data => { ...@@ -3470,7 +3563,7 @@ tls.getProtocol().then(data => {
getCipherSuite(callback: AsyncCallback\<Array\<string\>\>): void getCipherSuite(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the cipher suite negotiated by both communication parties after a TLSSocket connection is established. This API uses an asynchronous callback to return the result. Obtains the cipher suite negotiated by both communication parties after a TLS socket connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3505,7 +3598,7 @@ tls.getCipherSuite((err, data) => { ...@@ -3505,7 +3598,7 @@ tls.getCipherSuite((err, data) => {
getCipherSuite(): Promise\<Array\<string\>\> getCipherSuite(): Promise\<Array\<string\>\>
Obtains the cipher suite negotiated by both communication parties after a TLSSocket connection is established. This API uses a promise to return the result. Obtains the cipher suite negotiated by both communication parties after a TLS socket connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3538,7 +3631,7 @@ tls.getCipherSuite().then(data => { ...@@ -3538,7 +3631,7 @@ tls.getCipherSuite().then(data => {
getSignatureAlgorithms(callback: AsyncCallback\<Array\<string\>\>): void getSignatureAlgorithms(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the signing algorithm negotiated by both communication parties after a TLSSocket connection is established. This API is applicable to two-way authentication. It uses an asynchronous callback to return the result. Obtains the signing algorithm negotiated by both communication parties after a TLS socket connection is established. This API is applicable to two-way authentication. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3571,7 +3664,7 @@ tls.getSignatureAlgorithms((err, data) => { ...@@ -3571,7 +3664,7 @@ tls.getSignatureAlgorithms((err, data) => {
getSignatureAlgorithms(): Promise\<Array\<string\>\> getSignatureAlgorithms(): Promise\<Array\<string\>\>
Obtains the signing algorithm negotiated by both communication parties after a TLSSocket connection is established. This API is applicable to two-way authentication. It uses a promise to return the result. Obtains the signing algorithm negotiated by both communication parties after a TLS socket connection is established. This API is applicable to two-way authentication. It uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3602,7 +3695,7 @@ tls.getSignatureAlgorithms().then(data => { ...@@ -3602,7 +3695,7 @@ tls.getSignatureAlgorithms().then(data => {
send(data: string, callback: AsyncCallback\<void\>): void send(data: string, callback: AsyncCallback\<void\>): void
Sends a message to the server after a TLSSocket connection is established. This API uses an asynchronous callback to return the result. Sends a message to the server after a TLS socket connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3640,7 +3733,7 @@ tls.send("xxxx", (err) => { ...@@ -3640,7 +3733,7 @@ tls.send("xxxx", (err) => {
send(data: string): Promise\<void\> send(data: string): Promise\<void\>
Sends a message to the server after a TLSSocket connection is established. This API uses a promise to return the result. Sends a message to the server after a TLS socket connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3681,7 +3774,7 @@ tls.send("xxxx").then(() => { ...@@ -3681,7 +3774,7 @@ tls.send("xxxx").then(() => {
close(callback: AsyncCallback\<void\>): void close(callback: AsyncCallback\<void\>): void
Closes a TLSSocket connection. This API uses an asynchronous callback to return the result. Closes a TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3717,7 +3810,7 @@ tls.close((err) => { ...@@ -3717,7 +3810,7 @@ tls.close((err) => {
close(): Promise\<void\> close(): Promise\<void\>
Closes a TLSSocket connection. This API uses a promise to return the result. Closes a TLS socket connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -3815,7 +3908,7 @@ let tlsServer = socket.constructTLSSocketServerInstance(); ...@@ -3815,7 +3908,7 @@ let tlsServer = socket.constructTLSSocketServerInstance();
## TLSSocketServer<sup>10+</sup> ## TLSSocketServer<sup>10+</sup>
Defines a TLSSocketServer connection. Before calling TLSSocketServer APIs, you need to call [socket.constructTLSSocketServerInstance](#socketconstructtlssocketserverinstance10) to create a **TLSSocketServer** object. Defines a TLS socket server connection. Before calling TLSSocketServer APIs, you need to call [socket.constructTLSSocketServerInstance](#socketconstructtlssocketserverinstance10) to create a **TLSSocketServer** object.
### listen<sup>10+</sup> ### listen<sup>10+</sup>
...@@ -3950,7 +4043,7 @@ tlsServer.listen(options).then(() => { ...@@ -3950,7 +4043,7 @@ tlsServer.listen(options).then(() => {
getState(callback: AsyncCallback\<SocketStateBase\>): void getState(callback: AsyncCallback\<SocketStateBase\>): void
Obtains the status of the TLSSocketServer connection upon successful listening. This API uses an asynchronous callback to return the result. Obtains the status of the TLS socket server connection upon successful listening. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -3961,7 +4054,7 @@ Obtains the status of the TLSSocketServer connection upon successful listening. ...@@ -3961,7 +4054,7 @@ Obtains the status of the TLSSocketServer connection upon successful listening.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[SocketStateBase](#socketstatebase7)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLSSocketServer connection is returned. If the operation fails, an error message is returned.| | callback | AsyncCallback\<[SocketStateBase](#socketstatebase7)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLS socket server connection is returned. If the operation fails, an error message is returned.|
**Error codes** **Error codes**
...@@ -4011,7 +4104,7 @@ tlsServer.getState((err, data) => { ...@@ -4011,7 +4104,7 @@ tlsServer.getState((err, data) => {
getState(): Promise\<SocketStateBase\> getState(): Promise\<SocketStateBase\>
Obtains the status of the TLSSocketServer connection upon successful listening. This API uses a promise to return the result. Obtains the status of the TLS socket server connection upon successful listening. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4071,7 +4164,7 @@ promise.then(() => { ...@@ -4071,7 +4164,7 @@ promise.then(() => {
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the TLSSocketServer connection upon successful listening. This API uses an asynchronous callback to return the result. Sets other properties of the TLS socket server connection upon successful listening. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4082,7 +4175,7 @@ Sets other properties of the TLSSocketServer connection upon successful listenin ...@@ -4082,7 +4175,7 @@ Sets other properties of the TLSSocketServer connection upon successful listenin
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------------------------ | | -------- | ------------------------------------ | ---- | ------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLSSocketServer connection. | | options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLS socket server connection. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
**Error codes** **Error codes**
...@@ -4141,7 +4234,7 @@ tlsServer.setExtraOptions({ ...@@ -4141,7 +4234,7 @@ tlsServer.setExtraOptions({
setExtraOptions(options: TCPExtraOptions): Promise\<void\> setExtraOptions(options: TCPExtraOptions): Promise\<void\>
Sets other properties of the TLSSocketServer connection upon successful listening. This API uses a promise to return the result. Sets other properties of the TLS socket server connection upon successful listening. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4152,7 +4245,7 @@ Sets other properties of the TLSSocketServer connection upon successful listenin ...@@ -4152,7 +4245,7 @@ Sets other properties of the TLSSocketServer connection upon successful listenin
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------ | ---- | ------------------------------- | | ------- | ------------------------------------ | ---- | ------------------------------- |
| options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLSSocketServer connection.| | options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLS socket server connection.|
**Return value** **Return value**
...@@ -4217,7 +4310,7 @@ promise.then(() => { ...@@ -4217,7 +4310,7 @@ promise.then(() => {
getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void
Obtains the local digital certificate after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. Obtains the local digital certificate after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4278,7 +4371,7 @@ tlsServer.getCertificate((err, data) => { ...@@ -4278,7 +4371,7 @@ tlsServer.getCertificate((err, data) => {
getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\> getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
Obtains the local digital certificate after a TLSSocketServer connection is established. This API uses a promise to return the result. Obtains the local digital certificate after a TLS socket server connection is established. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4338,7 +4431,7 @@ tlsServer.getCertificate().then(data => { ...@@ -4338,7 +4431,7 @@ tlsServer.getCertificate().then(data => {
getProtocol(callback: AsyncCallback\<string\>): void getProtocol(callback: AsyncCallback\<string\>): void
Obtains the communication protocol version after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. Obtains the communication protocol version after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4399,7 +4492,7 @@ tlsServer.getProtocol((err, data) => { ...@@ -4399,7 +4492,7 @@ tlsServer.getProtocol((err, data) => {
getProtocol():Promise\<string\> getProtocol():Promise\<string\>
Obtains the communication protocol version after a TLSSocketServer connection is established. This API uses a promise to return the result. Obtains the communication protocol version after a TLS socket server connection is established. This API uses a promise to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4453,11 +4546,11 @@ tlsServer.getProtocol().then(data => { ...@@ -4453,11 +4546,11 @@ tlsServer.getProtocol().then(data => {
}); });
``` ```
### on('connect') ### on('connect')<sup>10+</sup>
on(type: 'connect', callback: Callback\<TLSSocketConnection\>): void on(type: 'connect', callback: Callback\<TLSSocketConnection\>): void
Enables listening for TLSSocketServer connection events. This API uses an asynchronous callback to return the result. Subscribes to TLS socket server connection events. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4508,14 +4601,15 @@ tlsServer.on('connect', function(data) { ...@@ -4508,14 +4601,15 @@ tlsServer.on('connect', function(data) {
}); });
``` ```
### off('connect') ### off('connect')<sup>10+</sup>
off(type: 'connect', callback?: Callback\<TLSSocketConnection\>): void off(type: 'connect', callback?: Callback\<TLSSocketConnection\>): void
Disables listening for TLSSocketServer connection events. This API uses an asynchronous callback to return the result. Unsubscribes from TLS socket server connection events. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > This API can be called only after **listen** is successfully called.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -4564,16 +4658,16 @@ tlsServer.listen(options).then(() => { ...@@ -4564,16 +4658,16 @@ tlsServer.listen(options).then(() => {
return; return;
}); });
tlsServer.on('connect', callback); tlsServer.on('connect', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tlsServer.off('connect', callback); tlsServer.off('connect', callback);
tlsServer.off('connect'); tlsServer.off('connect');
``` ```
### on('error') ### on('error')<sup>10+</sup>
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
Enables listening for **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result. Subscribes to **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> This API can be called only after **listen** is successfully called. > This API can be called only after **listen** is successfully called.
...@@ -4624,14 +4718,15 @@ tlsServer.on('error', err => { ...@@ -4624,14 +4718,15 @@ tlsServer.on('error', err => {
}); });
``` ```
### off('error') ### off('error')<sup>10+</sup>
off(type: 'error', callback?: ErrorCallback): void off(type: 'error', callback?: ErrorCallback): void
Disables listening for **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result. Unsubscribes from **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > This API can be called only after **listen** is successfully called.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -4680,7 +4775,7 @@ tlsServer.listen(options).then(() => { ...@@ -4680,7 +4775,7 @@ tlsServer.listen(options).then(() => {
return; return;
}); });
tlsServer.on('error', callback); tlsServer.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tlsServer.off('error', callback); tlsServer.off('error', callback);
tlsServer.off('error'); tlsServer.off('error');
``` ```
...@@ -4704,7 +4799,7 @@ Defines a **TLSSocketConnection** object, that is, the connection between the TL ...@@ -4704,7 +4799,7 @@ Defines a **TLSSocketConnection** object, that is, the connection between the TL
send(data: string, callback: AsyncCallback\<void\>): void send(data: string, callback: AsyncCallback\<void\>): void
Sends a message to the client after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. Sends a message to the client after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -4712,7 +4807,7 @@ Sends a message to the client after a TLSSocketServer connection is established. ...@@ -4712,7 +4807,7 @@ Sends a message to the client after a TLSSocketServer connection is established.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------------ | | -------- | --------------------- | ---- | ------------------------------------------------ |
| data | string | Yes | Parameters for sending data over the TLSSocketServer connection. | | data | string | Yes | Parameters for sending data over the TLS socket server connection. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
**Error codes** **Error codes**
...@@ -4767,7 +4862,7 @@ tlsServer.on('connect', function(client) { ...@@ -4767,7 +4862,7 @@ tlsServer.on('connect', function(client) {
send(data: string): Promise\<void\> send(data: string): Promise\<void\>
Sends a message to the server after a TLSSocketServer connection is established. This API uses a promise to return the result. Sends a message to the server after a TLS socket server connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -4775,7 +4870,7 @@ Sends a message to the server after a TLSSocketServer connection is established. ...@@ -4775,7 +4870,7 @@ Sends a message to the server after a TLSSocketServer connection is established.
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------- | | ------ | ------ | ---- | ------------------------------------- |
| data | string | Yes | Parameters required for the TLSSocketServer connection.| | data | string | Yes | Parameters required for the TLS socket server connection.|
**Return value** **Return value**
...@@ -4836,7 +4931,7 @@ tlsServer.on('connect', function(client) { ...@@ -4836,7 +4931,7 @@ tlsServer.on('connect', function(client) {
close(callback: AsyncCallback\<void\>): void close(callback: AsyncCallback\<void\>): void
Closes a TLSSocketServer connection. This API uses an asynchronous callback to return the result. Closes a TLS socket server connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -4897,7 +4992,7 @@ tlsServer.on('connect', function(client) { ...@@ -4897,7 +4992,7 @@ tlsServer.on('connect', function(client) {
close(): Promise\<void\> close(): Promise\<void\>
Closes a TLSSocketServer connection. This API uses a promise to return the result. Closes a TLS socket server connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -4958,7 +5053,7 @@ tlsServer.on('connect', function(client) { ...@@ -4958,7 +5053,7 @@ tlsServer.on('connect', function(client) {
getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void
Obtains the remote address of a TLSSocketServer connection. This API uses an asynchronous callback to return the result. Obtains the remote address of a TLS socket server connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5017,7 +5112,7 @@ tlsServer.on('connect', function(client) { ...@@ -5017,7 +5112,7 @@ tlsServer.on('connect', function(client) {
getRemoteAddress(): Promise\<NetAddress\> getRemoteAddress(): Promise\<NetAddress\>
Obtains the remote address of a TLSSocketServer connection. This API uses a promise to return the result. Obtains the remote address of a TLS socket server connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5075,7 +5170,7 @@ tlsServer.on('connect', function(client) { ...@@ -5075,7 +5170,7 @@ tlsServer.on('connect', function(client) {
getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void
Obtains the digital certificate of the peer end after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. It applies only to the scenario where the client sends a certificate to the server. Obtains the digital certificate of the peer end after a TLS socket server connection is established. This API uses an asynchronous callback to return the result. It applies only to the scenario where the client sends a certificate to the server.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5134,7 +5229,7 @@ tlsServer.on('connect', function(client) { ...@@ -5134,7 +5229,7 @@ tlsServer.on('connect', function(client) {
getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\> getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
Obtains the digital certificate of the peer end after a TLSSocketServer connection is established. This API uses a promise to return the result. It applies only to the scenario where the client sends a certificate to the server. Obtains the digital certificate of the peer end after a TLS socket server connection is established. This API uses a promise to return the result. It applies only to the scenario where the client sends a certificate to the server.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5192,7 +5287,7 @@ tlsServer.on('connect', function(client) { ...@@ -5192,7 +5287,7 @@ tlsServer.on('connect', function(client) {
getCipherSuite(callback: AsyncCallback\<Array\<string\>\>): void getCipherSuite(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the cipher suite negotiated by both communication parties after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. Obtains the cipher suite negotiated by both communication parties after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5253,7 +5348,7 @@ tlsServer.on('connect', function(client) { ...@@ -5253,7 +5348,7 @@ tlsServer.on('connect', function(client) {
getCipherSuite(): Promise\<Array\<string\>\> getCipherSuite(): Promise\<Array\<string\>\>
Obtains the cipher suite negotiated by both communication parties after a TLSSocketServer connection is established. This API uses a promise to return the result. Obtains the cipher suite negotiated by both communication parties after a TLS socket server connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5313,7 +5408,7 @@ tlsServer.on('connect', function(client) { ...@@ -5313,7 +5408,7 @@ tlsServer.on('connect', function(client) {
getSignatureAlgorithms(callback: AsyncCallback\<Array\<string\>\>): void getSignatureAlgorithms(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the signing algorithm negotiated by both communication parties after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. Obtains the signing algorithm negotiated by both communication parties after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5372,7 +5467,7 @@ tlsServer.on('connect', function(client) { ...@@ -5372,7 +5467,7 @@ tlsServer.on('connect', function(client) {
getSignatureAlgorithms(): Promise\<Array\<string\>\> getSignatureAlgorithms(): Promise\<Array\<string\>\>
Obtains the signing algorithm negotiated by both communication parties after a TLSSocketServer connection is established. This API uses a promise to return the result. Obtains the signing algorithm negotiated by both communication parties after a TLS socket server connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5430,7 +5525,7 @@ tlsServer.on('connect', function(client) { ...@@ -5430,7 +5525,7 @@ tlsServer.on('connect', function(client) {
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. Subscribes to **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5491,10 +5586,10 @@ tlsServer.on('connect', function(client) { ...@@ -5491,10 +5586,10 @@ tlsServer.on('connect', function(client) {
off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. Unsubscribes from **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5551,7 +5646,7 @@ tlsServer.listen(options).then(() => { ...@@ -5551,7 +5646,7 @@ tlsServer.listen(options).then(() => {
}); });
tlsServer.on('connect', function(client) { tlsServer.on('connect', function(client) {
client.on('message', callback); client.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('message', callback); client.off('message', callback);
client.off('message'); client.off('message');
}); });
...@@ -5561,7 +5656,7 @@ tlsServer.on('connect', function(client) { ...@@ -5561,7 +5656,7 @@ tlsServer.on('connect', function(client) {
on(type: 'close', callback: Callback\<void\>): void on(type: 'close', callback: Callback\<void\>): void
Enables listening for **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. Subscribes to **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5615,10 +5710,10 @@ tlsServer.on('connect', function(client) { ...@@ -5615,10 +5710,10 @@ tlsServer.on('connect', function(client) {
on(type: 'close', callback: Callback\<void\>): void on(type: 'close', callback: Callback\<void\>): void
Disables listening for **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. Unsubscribes from **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5668,7 +5763,7 @@ tlsServer.listen(options).then(() => { ...@@ -5668,7 +5763,7 @@ tlsServer.listen(options).then(() => {
}); });
tlsServer.on('connect', function(client) { tlsServer.on('connect', function(client) {
client.on('close', callback); client.on('close', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('close', callback); client.off('close', callback);
client.off('close'); client.off('close');
}); });
...@@ -5678,7 +5773,7 @@ tlsServer.on('connect', function(client) { ...@@ -5678,7 +5773,7 @@ tlsServer.on('connect', function(client) {
on(type: 'error', callback: ErrorCallback): void on(type: 'error', callback: ErrorCallback): void
Enables listening for **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. Subscribes to **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5732,10 +5827,10 @@ tlsServer.on('connect', function(client) { ...@@ -5732,10 +5827,10 @@ tlsServer.on('connect', function(client) {
off(type: 'error', callback?: ErrorCallback): void off(type: 'error', callback?: ErrorCallback): void
Disables listening for **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result. Unsubscribes from **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE** > **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. > You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -5785,7 +5880,7 @@ tlsServer.listen(options).then(() => { ...@@ -5785,7 +5880,7 @@ tlsServer.listen(options).then(() => {
}); });
tlsServer.on('connect', function(client) { tlsServer.on('connect', function(client) {
client.on('error', callback); client.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events. // You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('error', callback); client.off('error', callback);
client.off('error'); client.off('error');
}); });
......
...@@ -137,7 +137,7 @@ Checks whether the application has the permission to access the device. ...@@ -137,7 +137,7 @@ Checks whether the application has the permission to access the device.
**Example** **Example**
```js ```js
let devicesName="1-1"; let devicesName= "1-1";
let bool = usb.hasRight(devicesName); let bool = usb.hasRight(devicesName);
console.log(bool); console.log(bool);
``` ```
...@@ -165,7 +165,7 @@ Requests the temporary permission for the application to access a USB device. Th ...@@ -165,7 +165,7 @@ Requests the temporary permission for the application to access a USB device. Th
**Example** **Example**
```js ```js
let devicesName="1-1"; let devicesName= "1-1";
usb.requestRight(devicesName).then((ret) => { usb.requestRight(devicesName).then((ret) => {
console.log(`requestRight = ${ret}`); console.log(`requestRight = ${ret}`);
}); });
...@@ -375,7 +375,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi ...@@ -375,7 +375,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example** **Example**
```js ```js
let param = new usb.USBControlParams(); let param = {
request: 0,
reqType: 0,
target:0,
value: 0,
index: 0,
data: null
};
usb.controlTransfer(devicepipe, param).then((ret) => { usb.controlTransfer(devicepipe, param).then((ret) => {
console.log(`controlTransfer = ${ret}`); console.log(`controlTransfer = ${ret}`);
}) })
...@@ -500,7 +507,7 @@ Converts the USB function list in the numeric mask format to a string in Device ...@@ -500,7 +507,7 @@ Converts the USB function list in the numeric mask format to a string in Device
**Example** **Example**
```js ```js
let funcs = usb.ACM | usb.ECM; let funcs = usb.FunctionType.ACM | usb.FunctionType.ECM;
let ret = usb.usbFunctionsToString(funcs); let ret = usb.usbFunctionsToString(funcs);
``` ```
...@@ -529,8 +536,12 @@ Sets the current USB function list in Device mode. ...@@ -529,8 +536,12 @@ Sets the current USB function list in Device mode.
**Example** **Example**
```js ```js
let funcs = usb.HDC; let funcs = usb.FunctionType.HDC;
let ret = usb.setCurrentFunctions(funcs); usb.setCurrentFunctions(funcs).then(() => {
console.info('usb setCurrentFunctions successfully.');
}).catch(err => {
console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message);
});
``` ```
## usb.getCurrentFunctions<sup>9+</sup> ## usb.getCurrentFunctions<sup>9+</sup>
...@@ -848,7 +859,7 @@ Enumerates power role types. ...@@ -848,7 +859,7 @@ Enumerates power role types.
| Name | Value | Description | | Name | Value | Description |
| ------ | ---- | ---------- | | ------ | ---- | ---------- |
| NONE | 0 | None | | NONE | 0 | None. |
| SOURCE | 1 | External power supply.| | SOURCE | 1 | External power supply.|
| SINK | 2 | Internal power supply.| | SINK | 2 | Internal power supply.|
...@@ -862,6 +873,6 @@ Enumerates data role types. ...@@ -862,6 +873,6 @@ Enumerates data role types.
| Name | Value | Description | | Name | Value | Description |
| ------ | ---- | ------------ | | ------ | ---- | ------------ |
| NONE | 0 | None | | NONE | 0 | None. |
| HOST | 1 | USB host.| | HOST | 1 | USB host.|
| DEVICE | 2 | USB device.| | DEVICE | 2 | USB device.|
...@@ -177,3 +177,21 @@ System resources are not loaded to the sandbox path of the application process. ...@@ -177,3 +177,21 @@ System resources are not loaded to the sandbox path of the application process.
**Solution** **Solution**
Check whether the application process contains the sandbox path of system resources. Check whether the application process contains the sandbox path of system resources.
## 9001010 Invalid Overlay Path
**Error Message**
Overlay resource path is invalid.
**Description**
This error code is reported if the specified overlay path is invalid.
**Possible Causes**
The path does not exist or is not in the installation path of the application.
**Solution**
Check the location of the specified overlay path.
...@@ -157,8 +157,9 @@ You must install **Node.js** and HPM on your local PC. The installation procedur ...@@ -157,8 +157,9 @@ You must install **Node.js** and HPM on your local PC. The installation procedur
2. Learn more about the distribution. 2. Learn more about the distribution.
1. Read carefully the information about the distribution to learn its application scenarios, features, components, usage, and customization methods. 1. Read carefully the information about the distribution to learn its application scenarios, features, components, usage, and customization methods.
2. Click **Download** if you want to download the distribution to your local PC. 2. Use either of the following modes to obtain the source code:
3. Click **Device component tailoring** if you want to add or delete components of the distribution. - Click **Download** if you want to download the distribution to your local PC.
- Click **Device component tailoring** if you want to add or delete components of the distribution.
**Figure 2** Example distribution **Figure 2** Example distribution
......
# AI Framework Development # AI Framework Development Guide
## **Overview** ## **Overview**
### Introduction ### Introduction
The AI subsystem is the part of OpenHarmony that provides native distributed AI capabilities. At the heart of the subsystem is a unified AI engine framework, which implements quick integration of AI algorithm plug-ins. The AI subsystem is the part of OpenHarmony that provides native distributed AI capabilities. At the heart of the subsystem is a unified AI engine framework, which implements quick integration of AI algorithm plug-ins.
The framework consists of the plug-in management, module management, and communication management modules, fulfilling lifecycle management and on-demand deployment of AI algorithms. Specifically, plug-in management implements lifecycle management, on-demand deployment, and quick integration of AI algorithm plug-ins; module management implements task scheduling and client instance management; communication management manages inter-process communication (IPC) between the client and server and data transmission between the AI engine and plug-ins. Under this framework, AI algorithm APIs will be standardized to facilitate distributed calling of AI capabilities. In addition, unified inference APIs will be provided to adapt to different inference framework hierarchies.
The framework consists of the plug-in management, module management, and communication management modules, fulfilling lifecycle management and on-demand deployment of AI algorithms. Specifically, plug-in management implements lifecycle management, on-demand deployment, and quick integration of AI algorithm plug-ins; module management implements task scheduling and client instance management; communication management manages inter-process communication (IPC) between the client and server and data transmission between the AI engine and plug-ins.
Under this framework, AI algorithm APIs will be standardized to facilitate distributed calling of AI capabilities. In addition, unified inference APIs will be provided to adapt to different inference framework hierarchies.
The following figure shows the AI engine framework. The following figure shows the AI engine framework.
**Figure 1** AI engine framework **Figure 1** AI engine framework
![en-us_image_0000001200128073](figures/en-us_image_0000001200128073.png) ![en-us_image_0000001200128073](figure/en-us_image_0000001200128073.png)
### Setting Up the Environment ### Setting Up the Environment
...@@ -22,11 +19,11 @@ The following figure shows the AI engine framework. ...@@ -22,11 +19,11 @@ The following figure shows the AI engine framework.
2. [Download the source code.](../get-code/sourcecode-acquire.md) 2. [Download the source code.](../get-code/sourcecode-acquire.md)
## Technical specifications ## Technical Specifications
### Code Management ### Code Management
The AI engine framework consists of three modules: **client**, **server**, and **common**. The client module provides the server connection management function. The SDK needs to encapsulate and call the public APIs provided by the client in the algorithm's external APIs. The server module provides functions such as plug-in loading and task management. Plug-ins are integrated using the plug-in APIs provided by the server. The common module provides platform-related operation methods, engine protocols, and tool classes for other modules. The AI engine framework consists of three modules: **client**, **server**, and **common**. The client module provides the server connection management function. An OpenHarmony SDK needs to encapsulate and call the public APIs provided by the client in the algorithm's external APIs. The server module provides functions such as plug-in loading and task management. Plug-ins are integrated using the plug-in APIs provided by the server. The common module provides platform-related operation methods, engine protocols, and tool classes for other modules.
The following figure shows the code dependency between modules of the AI engine framework. The following figure shows the code dependency between modules of the AI engine framework.
...@@ -34,12 +31,12 @@ The following figure shows the code dependency between modules of the AI engine ...@@ -34,12 +31,12 @@ The following figure shows the code dependency between modules of the AI engine
**Figure 2** Code dependency **Figure 2** Code dependency
![en-us_image_0000001151931738](figures/en-us_image_0000001151931738.jpg) ![en-us_image_0000001151931738](figure/en-us_image_0000001151931738.jpg)
#### Recommendation: Develop plug-ins and SDKs in the directories specified by the AI engine. #### Recommendation: Develop plug-ins and OpenHarmony SDKs in the directories specified by the AI engine.
In the overall planning of the AI engine framework, SDKs are a part of the client, and plug-ins are called by the server and are considered a part of the server. Therefore, the following directories have been planned for plug-in and SDK development in the AI engine framework: In the overall planning of the AI engine framework, OpenHarmony SDKs are a part of the client, and plug-ins are called by the server and are considered a part of the server. Therefore, the following directories have been planned for plug-in and OpenHarmony SDK development in the AI engine framework:
- SDK code directory: //foundation/ai/engine/services/client/algorithm_sdk - SDK code directory: //foundation/ai/engine/services/client/algorithm_sdk
...@@ -56,7 +53,7 @@ In the overall planning of the AI engine framework, SDKs are a part of the clien ...@@ -56,7 +53,7 @@ In the overall planning of the AI engine framework, SDKs are a part of the clien
#### Rule: Store all external APIs provided by plug-ins in the **interfaces/kits** directory of the AI subsystem. #### Rule: Store all external APIs provided by plug-ins in the **interfaces/kits** directory of the AI subsystem.
The AI subsystem exposes its capabilities through external APIs of SDKs. According to API management requirements of OpenHarmony, store all external APIs of SDKs in the **interfaces/kits** directory of the subsystem. Currently, the external APIs of plug-ins of the AI subsystem are stored in the **//foundation/ai/engine/interfaces/kits** directory. You can add a sub-directory for each newly added plug-in in this directory. For example, if you add a CV plug-in, then store its external APIs in the **//foundation/ai/engine/interfaces/kits/cv** directory. The AI subsystem exposes its capabilities through external APIs of OpenHarmony SDKs. According to API management requirements of OpenHarmony, store all external APIs of the SDK in the **interfaces/kits** directory of the subsystem. Currently, the external APIs of plug-ins of the AI subsystem are stored in the **//foundation/ai/engine/interfaces/kits** directory. You can add a sub-directory for each newly added plug-in in this directory. For example, if you add a CV plug-in, then store its external APIs in the **//foundation/ai/engine/interfaces/kits/cv** directory.
#### Rule: Make sure that plug-in build results are stored in the **/usr/lib** directory. #### Rule: Make sure that plug-in build results are stored in the **/usr/lib** directory.
...@@ -65,14 +62,14 @@ Plug-in loading on the server uses the dlopen mode and can only be performed in ...@@ -65,14 +62,14 @@ Plug-in loading on the server uses the dlopen mode and can only be performed in
### Naming rule ### Naming rule
#### Rule: Name an SDK in the format of **domain\_keyword&lt;*other information 1*\_*other information 2*\_…&gt;\_sdk.so**. #### Rule: Name an SDK in the format of **domain_keyword<_other information 1_other information 2_...>_sdk.so**.
You are advised to use the commonly known abbreviations for domains. For example, use **cv** for image and video, **asr** for voice recognition, and **translation** for text translation. Add one if there is no available abbreviation for a domain. Use keywords that accurately describe the algorithm capability of the plug-in. For example, use **keyword\_spotting** for wakeup keyword spotting (KWS). Add other information, such as the supported chip type and applicable region, between **keyword** and **sdk**, with each of them separated by an underscore (\_). Note that the name of a SDK must end with **\_sdk**. You are advised to use the commonly known abbreviations for domains. For example, use **cv** for image and video, **asr** for voice recognition, and **translation** for text translation. Add one if there is no available abbreviation for a domain. Use keywords that accurately describe the algorithm capability of the plug-in. For example, use **keyword\_spotting** for wakeup keyword spotting (KWS). Add other information, such as the supported chip type and applicable region, between **keyword** and **sdk**, with each of them separated by an underscore (\_). Note that the name of an SDK must end with **\_sdk**.
For example, if the SDK for the KWS plug-in supports only the Kirin 9000 chipset and is applicable only in China, then name the SDK as follows: **asr\_keyword\_spotting\_kirin9000\_china\_sdk.so**. For example, if the SDK for the KWS plug-in supports only the Kirin 9000 chipset and is applicable only in China, then name the SDK as follows: **asr\_keyword\_spotting\_kirin9000\_china\_sdk.so**.
#### Rule: Name a plug-in in the format of **domain\_keyword&lt;*other information 1*\_*other information 2*\_…&gt;.so**. #### Rule: Name a plug-in in the format of **domain_keyword<_other information 1_other information 2_...>.so**.
There is a one-to-one mapping between plug-ins and SDKs. Therefore, the definitions and requirements of terms such as the domain, keyword, and other information in plug-in names are the same as those in SDK names. The only difference is that the name of the SDK ends with **\_sdk** additionally. For example, if the plug-in is named **asr\_keyword\_spotting.so**, the corresponding SDK is named **asr\_keyword\_spotting\_sdk.so**. There is a one-to-one mapping between plug-ins and SDKs. Therefore, the definitions and requirements of terms such as the domain, keyword, and other information in plug-in names are the same as those in SDK names. The only difference is that the name of the SDK ends with **\_sdk** additionally. For example, if the plug-in is named **asr\_keyword\_spotting.so**, the corresponding SDK is named **asr\_keyword\_spotting\_sdk.so**.
...@@ -151,14 +148,19 @@ retCode = ProcessEncode(dataInfo, arg1, arg2, arg3) // The number of parameters ...@@ -151,14 +148,19 @@ retCode = ProcessEncode(dataInfo, arg1, arg2, arg3) // The number of parameters
retCode = ProcessDecode(dataInfo, arg1, arg2, arg3) // The number of parameters can be flexible. retCode = ProcessDecode(dataInfo, arg1, arg2, arg3) // The number of parameters can be flexible.
``` ```
> **NOTE** Note:
>
> - The sequence of parameters must be the same during encoding and decoding. - The sequence of parameters must be the same during encoding and decoding.
> - After encoding, the memory used by **dataInfo** needs to be manually released by the caller.
> - The memory is managed and released separately on the server and the client. - After encoding, the memory used by **dataInfo** needs to be manually released by the caller.
> - If a pointer contains the shared memory, no extra processing is required.
> - If other types of pointers are used, you need to dereference them before using **ProcessEncode** or **ProcessDecode**. - The memory is managed and released separately on the server and the client.
> - The codec module has not been adapted to the **class** data type and therefore it is not recommended.
- If a pointer contains the shared memory, no extra processing is required.
- If other types of pointers are used, you need to dereference them before using **ProcessEncode** or **ProcessDecode**.
- The codec module has not been adapted to the **class** data type and therefore it is not recommended.
#### Rule: Release the memory used by the encoded or decoded parameters in the SDK. Otherwise, a memory leakage occurs. #### Rule: Release the memory used by the encoded or decoded parameters in the SDK. Otherwise, a memory leakage occurs.
...@@ -249,7 +251,7 @@ The following table describes the data structure of **ConfigInfo**, **ClientInfo ...@@ -249,7 +251,7 @@ The following table describes the data structure of **ConfigInfo**, **ClientInfo
| ConfigInfo | Algorithm configuration item information| **const&nbsp;char&nbsp;\*description**: body of configuration item information. | | ConfigInfo | Algorithm configuration item information| **const&nbsp;char&nbsp;\*description**: body of configuration item information. |
| ClientInfo | Client information.| **long&nbsp;long&nbsp;clientVersion**: client version number. This parameter is not used currently.<br>**int&nbsp;clientId**: client ID.<br>**int&nbsp;sessionId**: session ID.<br>**uid\_t&nbsp;serverUid**: server UID.<br>**uid\_t&nbsp;clientUid**: client UID.<br>**int&nbsp;extendLen**: length of the extended information (**extendMsg**).<br>**unsigned&nbsp;char&nbsp;\*extendMsg**: body of the extended information. | | ClientInfo | Client information.| **long&nbsp;long&nbsp;clientVersion**: client version number. This parameter is not used currently.<br>**int&nbsp;clientId**: client ID.<br>**int&nbsp;sessionId**: session ID.<br>**uid\_t&nbsp;serverUid**: server UID.<br>**uid\_t&nbsp;clientUid**: client UID.<br>**int&nbsp;extendLen**: length of the extended information (**extendMsg**).<br>**unsigned&nbsp;char&nbsp;\*extendMsg**: body of the extended information. |
| AlgorithmInfo | Algorithm information| **long&nbsp;long&nbsp;clientVersion**: client version number. This parameter is not used currently.<br>**bool&nbsp;isAsync**: whether asynchronous execution is used.<br>**int&nbsp;algorithmType**: algorithm type ID allocated by the AI engine framework based on the plug-in loading sequence.<br>**long&nbsp;long&nbsp;algorithmVersion**: algorithm version number.<br>**bool&nbsp;isCloud**: whether to migrate data to the cloud. This parameter is not used currently.<br>**int&nbsp;operateId**: execution ID. This parameter is not used currently.<br>**int&nbsp;requestId**: request ID, which identifies each request and corresponds to the execution result.<br>**int&nbsp;extendLen**: length of the extended information (**extendMsg**).<br>**unsigned&nbsp;char&nbsp;\*extendMsg**: body of the extended information. | | AlgorithmInfo | Algorithm information| **long&nbsp;long&nbsp;clientVersion**: client version number. This parameter is not used currently.<br>**bool&nbsp;isAsync**: whether asynchronous execution is used.<br>**int&nbsp;algorithmType**: algorithm type ID allocated by the AI engine framework based on the plug-in loading sequence.<br>**long&nbsp;long&nbsp;algorithmVersion**: algorithm version number.<br>**bool&nbsp;isCloud**: whether to migrate data to the cloud. This parameter is not used currently.<br>**int&nbsp;operateId**: execution ID. This parameter is not used currently.<br>**int&nbsp;requestId**: request ID, which identifies each request and corresponds to the execution result.<br>**int&nbsp;extendLen**: length of the extended information (**extendMsg**).<br>**unsigned&nbsp;char&nbsp;\*extendMsg**: body of the extended information. |
| DataInfo | Algorithm input parameter configuration information (**inputInfo**) and output parameter configuration information (**outputInfo**)| **unsigned&nbsp;char&nbsp;\*data**: data subject.<br>**int&nbsp;length**: data length. | | DataInfo | Algorithm input parameter configuration information (**inputInfo**)<br>and output parameter configuration information (**outputInfo**)| **unsigned&nbsp;char&nbsp;\*data**: data subject.<br>**int&nbsp;length**: data length. |
For details about the development process, see the development example of the [KWS SDK](#kws-sdk). For details about the development process, see the development example of the [KWS SDK](#kws-sdk).
...@@ -313,7 +315,7 @@ The following table describes the attributes of the **Response** class. ...@@ -313,7 +315,7 @@ The following table describes the attributes of the **Response** class.
| Attribute| Description| Default Value| | Attribute| Description| Default Value|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| innerSequenceId_ | Type: long&nbsp;long<br>**Function**: reserved| 0 | | innerSequenceId_ | **Type**: long&nbsp;long<br>**Function**: reserved| 0 |
| requestId_ | **Type**: int<br>**Function**: Indicates the request sequence, which is used to bind the return result.| 0 | | requestId_ | **Type**: int<br>**Function**: Indicates the request sequence, which is used to bind the return result.| 0 |
| retCode__ | **Type**: int<br>**Function**: Indicates the inference result code of the asynchronous algorithm.| 0 | | retCode__ | **Type**: int<br>**Function**: Indicates the inference result code of the asynchronous algorithm.| 0 |
| retDesc_ | **Type**: string<br>**Function**: reserved| - | | retDesc_ | **Type**: string<br>**Function**: reserved| - |
...@@ -454,10 +456,11 @@ The preceding code implements the **IPlugin** APIs provided by the server. The f ...@@ -454,10 +456,11 @@ The preceding code implements the **IPlugin** APIs provided by the server. The f
| AieClientGetOption | GetOption | Obtains algorithm-related configuration items. For KWS, this API can obtain the input and output scale of the KWS model. The input scale is the MFCC feature (fixed value: **4000**) required by the KWS model, and the output scale is the confidence (fixed value: **2**) of the result.| | AieClientGetOption | GetOption | Obtains algorithm-related configuration items. For KWS, this API can obtain the input and output scale of the KWS model. The input scale is the MFCC feature (fixed value: **4000**) required by the KWS model, and the output scale is the confidence (fixed value: **2**) of the result.|
| AieClientRelease | Release | Releases the algorithm model. For KWS, this API releases the specified algorithm model and clears the dynamic memory in the feature processor.| | AieClientRelease | Release | Releases the algorithm model. For KWS, this API releases the specified algorithm model and clears the dynamic memory in the feature processor.|
> **NOTE** Note:
>
> - The **AieClientInit** and **AieClientDestroy** APIs are used to connect to and disconnect from the server, respectively. They are not called in the plug-in algorithm and therefore do not need to be defined in the plug-in. 1. The **AieClientInit** and **AieClientDestroy** APIs are used to connect to and disconnect from the server, respectively. They are not called in the plug-in algorithm and therefore do not need to be defined in the plug-in.
> - The KWS plug-in needs to use the **PLUGIN\_INTERFACE\_IMPL** statement to expose the function pointer. Otherwise, the plug-in cannot be properly loaded.
2. The KWS plug-in needs to use the **PLUGIN\_INTERFACE\_IMPL** statement to expose the function pointer. Otherwise, the plug-in cannot be properly loaded.
``` ```
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
### Function Introduction ### Function Introduction
Neural Network Runtime (NNRt) functions as a bridge to connect the upper-layer AI inference framework and bottom-layer acceleration chips, implementing cross-chip inference computing of AI models. Neural Network Runtime (NNRt) functions as a bridge to connect the upper-layer AI inference framework and underlying acceleration chips, implementing cross-chip inference computing of AI models.
With the open APIs provided by NNRt, chip vendors can connect their dedicated acceleration chips to NNRt to access the OpenHarmony ecosystem. NNRt opens HDIs for chip vendors to connect dedicated acceleration chips to NNRt to interconnect with the OpenHarmony ecosystem.
### Basic Concepts ### Basic Concepts
Before you get started, it would be helpful for you to have a basic understanding of the following concepts: Before you get started, it would be helpful for you to have a basic understanding of the following concepts:
...@@ -26,40 +26,36 @@ NNRt connects to device chips through HDIs, which implement cross-process commun ...@@ -26,40 +26,36 @@ NNRt connects to device chips through HDIs, which implement cross-process commun
![NNRt architecture](./figures/nnrt_arch_diagram.png) ![NNRt architecture](./figures/nnrt_arch_diagram.png)
The NNRt architecture consists of three layers: AI applications at the application layer, AI inference framework and NNRt at the system layer, and device services at the chip layer. To use a dedicated acceleration chip model for inference, an AI application needs to call the dedicated acceleration chip at the bottom layer through the AI inference framework and NNRt. NNRt is responsible for adapting to various dedicated acceleration chips at the bottom layer. It opens standard and unified HDIs for various chips to access the OpenHarmony ecosystem. The NNRt architecture consists of three layers: AI applications at the application layer, AI inference framework and NNRt at the system layer, and device services at the chip layer. To use a dedicated acceleration chip model for inference, an AI application needs to call the underlying dedicated AI acceleration chip through the AI inference framework and NNRt. NNRt is responsible for adapting to various underlying dedicated acceleration chips. It opens standard and unified HDIs for various AI acceleration chips to access the OpenHarmony ecosystem. In addition, NNRt opens standard and unified APIs to connect to various upper-layer AI inference frameworks.
During program running, the AI application, AI inference framework, and NNRt reside in the user process, and the underlying device services reside in the service process. NNRt implements the HDI client and the service side implements HDI Service to fulfill cross-process communication. During program running, the AI application, AI inference framework, and NNRt reside in the user process, and the underlying AI chip device services reside in the HDI service process. NNRt implements the HDI client and the service side implements HDI Service to fulfill cross-process communication through the Hardware Driver Foundation (HDF) subsystem.
## How to Develop ## How to Develop
### Application Scenario ### Application Scenario
Suppose you are connecting an AI acceleration chip, for example, RK3568, to NNRt. The following describes how to connect the RK3568 chip to NNRt through the HDI to implement AI model inference. Suppose you are connecting an AI acceleration chip, for example, RK3568, to NNRt. The following exemplifies how to connect the RK3568 chip to NNRt through HDI V2.0 to implement AI model inference. The process is similar for HDI V1.0.
> **NOTE**<br>In this application scenario, the connection of the RK3568 chip to NNRt is implemented by utilizing the CPU operator of MindSpore Lite, instead of writing the CPU driver. This is the reason why the following development procedure depends on the dynamic library and header file of MindSpore Lite. In practice, the development does not depend on any library or header file of MindSpore Lite. > **NOTE**<br>In this tutorial, the purpose of connecting the RK3568 chip to NNRt is to utilize the runtime and CPU operators of MindSpore Lite, instead of implementing the CPU driver. Therefore, the RK3568 chip depends on the dynamic libraries and header files of MindSpore Lite. In practice, the RK3568 chip does not depend on any library or header file of MindSpore Lite.
### Development Flowchart ### Development Flowchart
The following figure shows the process of connecting a dedicated acceleration chip to NNRt. The following figure shows the process of connecting a dedicated AI acceleration chip to NNRt.
**Figure 2** NNRt development flowchart **Figure 2** Process of connecting a dedicated AI acceleration chip to NNRt
![NNRt development flowchart](./figures/nnrt_dev_flow.png) ![Process of connecting a dedicated AI acceleration chip to NNRt](./figures/nnrt_dev_flow.png)
### Development Procedure ### Development Procedure
The following uses the RK3568 chip as an example to describe the development procedure.
To connect the acceleration chip to NNRt, perform the development procedure below.
#### Generating the HDI Header File #### Generating the HDI Header File
Download the OpenHarmony source code from the open source community, build the `drivers_interface` component, and generate the HDI header file. Download the OpenHarmony source code from the open source community, build the `drivers_interface` component, and generate the HDI header file.
1. [Download the source code](../get-code/sourcecode-acquire.md). 1. [Download the source code](../get-code/sourcecode-acquire.md).
2. Build the IDL file of the HDI. 2. Go to the root directory of OpenHarmony source code, and compile the IDL API file of NNRt.
```shell ```shell
./build.sh --product-name productname –ccache --build-target drivers_interface_nnrt ./build.sh --product-name rk3568 –ccache --build-target drivers_interface_nnrt
``` ```
> **NOTE**<br>**productname** indicates the product name. In this example, the product name is **RK3568**.
When the build is complete, the HDI header file is generated in `out/rk3568/gen/drivers/interface/nnrt`. The default programming language is C++. To generate a header file for the C programming language, run the following command to set the `language` field in the `drivers/interface/nnrt/v1_0/BUILD.gn` file before starting the build: After the compilation is complete, an HDI header file of the C++ language is generated in the `out/rk3568/gen/drivers/interface/nnrt/v2_0` directory. To generate a header file of the C language, run the following command to set the language field in the `drivers/interface/nnrt/v2_0/BUILD.gn` file before starting compilation:
```shell ```shell
language = "c" language = "c"
...@@ -68,13 +64,13 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -68,13 +64,13 @@ Download the OpenHarmony source code from the open source community, build the `
The directory of the generated header file is as follows: The directory of the generated header file is as follows:
```text ```text
out/rk3568/gen/drivers/interface/nnrt out/rk3568/gen/drivers/interface/nnrt
└── v1_0 └── v2_0
├── drivers_interface_nnrt__libnnrt_proxy_1.0_external_deps_temp.json ├── drivers_interface_nnrt__libnnrt_proxy_2.0_external_deps_temp.json
├── drivers_interface_nnrt__libnnrt_stub_1.0_external_deps_temp.json ├── drivers_interface_nnrt__libnnrt_stub_2.0_external_deps_temp.json
├── innrt_device.h # Header file of the HDI ├── innrt_device.h # Header file of the HDI
├── iprepared_model.h # Header file of the AI model ├── iprepared_model.h # Header file of the AI model
├── libnnrt_proxy_1.0__notice.d ├── libnnrt_proxy_2.0__notice.d
├── libnnrt_stub_1.0__notice.d ├── libnnrt_stub_2.0__notice.d
├── model_types.cpp # Implementation file for AI model structure definition ├── model_types.cpp # Implementation file for AI model structure definition
├── model_types.h # Header file for AI model structure definition ├── model_types.h # Header file for AI model structure definition
├── nnrt_device_driver.cpp # Device driver implementation example ├── nnrt_device_driver.cpp # Device driver implementation example
...@@ -85,7 +81,7 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -85,7 +81,7 @@ Download the OpenHarmony source code from the open source community, build the `
├── nnrt_device_stub.cpp ├── nnrt_device_stub.cpp
├── nnrt_device_stub.h ├── nnrt_device_stub.h
├── nnrt_types.cpp # Implementation file for data type definition ├── nnrt_types.cpp # Implementation file for data type definition
├── nnrt_types.h # Header file for data type definition ├── nnrt_types.h # Header file for data type definitions
├── node_attr_types.cpp # Implementation file for AI model operator attribute definition ├── node_attr_types.cpp # Implementation file for AI model operator attribute definition
├── node_attr_types.h # Header file for AI model operator attribute definition ├── node_attr_types.h # Header file for AI model operator attribute definition
├── prepared_model_proxy.cpp ├── prepared_model_proxy.cpp
...@@ -98,55 +94,58 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -98,55 +94,58 @@ Download the OpenHarmony source code from the open source community, build the `
#### Implementing the HDI Service #### Implementing the HDI Service
1. Create a development directory in `drivers/peripheral`. The structure of the development directory is as follows: 1. Go to the root directory of OpenHarmony source code, and create the `nnrt` folder in the `drivers/peripheral` directory for HDI service development. The directory structure is as follows:
```text ```text
drivers/peripheral/nnrt drivers/peripheral/nnrt
├── BUILD.gn # Code build script
├── bundle.json ├── bundle.json
└── hdi_cpu_service # Customized directory ├── v2_0
├── BUILD.gn # Code build script ├── BUILD.gn # Code build script
├── include └── hdi_cpu_service # Customized directory
│ ├── nnrt_device_service.h # Header file for device services ├── BUILD.gn # Code build script
│ ├── node_functions.h # Optional, depending on the actual implementation ├── include
│ ├── node_registry.h # Optional, depending on the actual implementation │ ├── nnrt_device_service.h # Header file for device services
│ └── prepared_model_service.h # Header file for AI model services │ ├── node_functions.h # Optional, depending on the actual implementation
└── src │ ├── node_registry.h # Optional, depending on the actual implementation
├── nnrt_device_driver.cpp # Implementation file for the device driver │ └── prepared_model_service.h # Header file for AI model services
├── nnrt_device_service.cpp # Implementation file for device services └── src
├── nnrt_device_stub.cpp # Optional, depending on the actual implementation ├── nnrt_device_driver.cpp # Implementation file for the device driver
├── node_attr_types.cpp # Optional, depending on the actual implementation ├── nnrt_device_service.cpp # Implementation file for device services
├── node_functions.cpp # Optional, depending on the actual implementation ├── nnrt_device_stub.cpp # Optional, depending on the actual implementation
├── node_registry.cpp # Optional, depending on the actual implementation ├── node_attr_types.cpp # Optional, depending on the actual implementation
└── prepared_model_service.cpp # Implementation file for AI model services ├── node_functions.cpp # Optional, depending on the actual implementation
├── node_registry.cpp # Optional, depending on the actual implementation
└── prepared_model_service.cpp # Implementation file for AI model services
``` ```
2. Implement the device driver. Unless otherwise required, you can directly use the `nnrt_device_driver.cpp` file generated in step 1. 2. Implement the device driver. Unless otherwise required, you can directly use the `nnrt_device_driver.cpp` file generated through IDL file compilation.
3. Implement service APIs. For details, see the `nnrt_device_service.cpp` and `prepared_model_service.cpp` implementation files. For details about the API definition, see [NNRt HDI Definitions](https://gitee.com/openharmony/drivers_interface/tree/master/nnrt). 3. Implement service APIs by referring to the `nnrt_device_service.cpp` and `prepared_model_service.cpp` files. For details about the API definitions, see [NNRt HDI Definitions](https://gitee.com/openharmony/drivers_interface/tree/master/nnrt).
4. Build the implementation files for device drivers and services as shared libraries. 4. Compile the implementation files for device drivers and services as shared libraries.
Create the `BUILD.gn` file with the following content in `drivers/peripheral/nnrt/hdi_cpu_service/`. For details about how to set related parameters, see [Compilation and Building](https://gitee.com/openharmony/build). Create the `BUILD.gn` file with the following content in the `drivers/peripheral/nnrt/v2_0/hdi_cpu_service/` directory. For details about how to set related parameters, see [Compilation and Building](https://gitee.com/openharmony/build).
```shell ```shell
import("//build/ohos.gni") import("//build/ohos.gni")
import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni") import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni")
ohos_shared_library("libnnrt_service_1.0") { ohos_shared_library("libnnrt_service_2.0") {
include_dirs = [] include_dirs = []
sources = [ sources = [
"src/nnrt_device_service.cpp", "src/nnrt_device_service.cpp",
"src/prepared_model_service.cpp",
"src/node_registry.cpp",
"src/node_functions.cpp", "src/node_functions.cpp",
"src/node_attr_types.cpp" "src/node_registry.cpp",
"src/prepared_model_service.cpp",
"src/shared_buffer_parser.cpp",
"src/validation.cpp",
] ]
public_deps = [ "//drivers/interface/nnrt/v1_0:nnrt_idl_headers" ]
external_deps = [ external_deps = [
"hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_single",
"c_utils:utils", "c_utils:utils",
"drivers_interface_nnrt:libnnrt_stub_2.0",
"hdf_core:libhdf_utils",
"hilog_native:libhilog",
"ipc:ipc_core",
] ]
install_images = [ chipset_base_dir ] install_images = [ chipset_base_dir ]
...@@ -157,15 +156,17 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -157,15 +156,17 @@ Download the OpenHarmony source code from the open source community, build the `
ohos_shared_library("libnnrt_driver") { ohos_shared_library("libnnrt_driver") {
include_dirs = [] include_dirs = []
sources = [ "src/nnr_device_driver.cpp" ] sources = [ "src/nnr_device_driver.cpp" ]
deps = [ "//drivers/peripheral/nnrt/hdi_cpu_service:libnnrt_service_1.0" ] deps = [ ":libnnrt_service_2.0" ]
external_deps = [ external_deps = [
"c_utils:utils",
"drivers_interface_nnrt:libnnrt_stub_2.0",
"hdf_core:libhdf_host", "hdf_core:libhdf_host",
"hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_ipc_adapter",
"hdf_core:libhdf_utils", "hdf_core:libhdf_utils",
"hiviewdfx_hilog_native:libhilog", "hdf_core:libhdi",
"ipc:ipc_single", "hilog_native:libhilog",
"c_utils:utils", "ipc:ipc_core",
] ]
install_images = [ chipset_base_dir ] install_images = [ chipset_base_dir ]
...@@ -176,22 +177,20 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -176,22 +177,20 @@ Download the OpenHarmony source code from the open source community, build the `
group("hdf_nnrt_service") { group("hdf_nnrt_service") {
deps = [ deps = [
":libnnrt_driver", ":libnnrt_driver",
":libnnrt_service_1.0", ":libnnrt_service_2.0",
] ]
} }
``` ```
Add `group("hdf_nnrt_service")` to the `drivers/peripheral/nnrt/BUILD.gn` file so that it can be referenced at a higher directory level. Add `group("hdf_nnrt_service")` to the `drivers/peripheral/nnrt/v2_0/BUILD.gn` file so that it can be referenced at a higher directory level.
```shell ```shell
if (defined(ohos_lite)) { if (defined(ohos_lite)) {
group("nnrt_entry") { group("nnrt_entry") {
deps = [ ] deps = []
} }
} else { } else {
group("nnrt_entry") { group("nnrt_entry") {
deps = [ deps = [ "./hdi_cpu_service:hdf_nnrt_service" ]
"./hdi_cpu_service:hdf_nnrt_service",
]
} }
} }
``` ```
...@@ -201,7 +200,7 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -201,7 +200,7 @@ Download the OpenHarmony source code from the open source community, build the `
{ {
"name": "drivers_peripheral_nnrt", "name": "drivers_peripheral_nnrt",
"description": "Neural network runtime device driver", "description": "Neural network runtime device driver",
"version": "3.2", "version": "4.0",
"license": "Apache License 2.0", "license": "Apache License 2.0",
"component": { "component": {
"name": "drivers_peripheral_nnrt", "name": "drivers_peripheral_nnrt",
...@@ -212,10 +211,10 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -212,10 +211,10 @@ Download the OpenHarmony source code from the open source community, build the `
"ram": "2048KB", "ram": "2048KB",
"deps": { "deps": {
"components": [ "components": [
"ipc", "c_utils",
"hdf_core", "hdf_core",
"hiviewdfx_hilog_native", "hilog_native",
"c_utils" "ipc"
], ],
"third_part": [ "third_part": [
"bounds_checking_function" "bounds_checking_function"
...@@ -223,7 +222,7 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -223,7 +222,7 @@ Download the OpenHarmony source code from the open source community, build the `
}, },
"build": { "build": {
"sub_component": [ "sub_component": [
"//drivers/peripheral/nnrt:nnrt_entry" "//drivers/peripheral/nnrt/v2_0:nnrt_entry"
], ],
"test": [ "test": [
], ],
...@@ -236,7 +235,7 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -236,7 +235,7 @@ Download the OpenHarmony source code from the open source community, build the `
#### Declaring the HDI Service #### Declaring the HDI Service
In the uhdf directory, declare the user-mode driver and services in the **.hcs** file of the corresponding product. For example, for the RK3568 chip, add the following configuration to the `vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs` file: In the `uhdf` directory, declare the user-mode driver and services in the `.hcs` file of the corresponding product. For example, for the RK3568 chip, add the following configuration to the `vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs` file:
```text ```text
nnrt :: host { nnrt :: host {
hostName = "nnrt_host"; hostName = "nnrt_host";
...@@ -254,7 +253,7 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -254,7 +253,7 @@ Download the OpenHarmony source code from the open source community, build the `
} }
} }
``` ```
> **NOTE**<BR>After modifying the `.hcs` file, you need to delete the `out` directory and build the file again for the modification to take effect. > **NOTE**<br>After modifying the `.hcs` file, you need to delete the `out` folder and compile the file again for the modification to take effect.
#### Configuring the User ID and Group ID of the Host Process #### Configuring the User ID and Group ID of the Host Process
In the scenario of creating an nnrt_host process, you need to configure the user ID and group ID of the corresponding process. The user ID is configured in the `base/startup/init/services/etc/passwd` file, and the group ID is configured in the `base/startup/init/services/etc/group` file. In the scenario of creating an nnrt_host process, you need to configure the user ID and group ID of the corresponding process. The user ID is configured in the `base/startup/init/services/etc/passwd` file, and the group ID is configured in the `base/startup/init/services/etc/group` file.
...@@ -268,23 +267,60 @@ Download the OpenHarmony source code from the open source community, build the ` ...@@ -268,23 +267,60 @@ Download the OpenHarmony source code from the open source community, build the `
#### Configuring SELinux #### Configuring SELinux
The SELinux feature has been enabled for the OpenHarmony. You need to configure SELinux rules for the new processes and services so that they can run the host process to access certain resources and release HDI services. The SELinux feature has been enabled for the OpenHarmony. You need to configure SELinux rules for the new processes and services so that they can run the host process to access certain resources, release HDI services, etc.
1. Add the following configuration to the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/public/hdf_service_contexts` file:
```text
# Add the security context configuration.
nnrt_device_service u:object_r:hdf_nnrt_device_service:s0
```
> **NOTE**<br>`nnrt_host` indicates the process name configured in [Declaring the HDI Service](#declaring-the-hdi-service).
2. Add the following configuration to the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/public/hdf_service.te` file:
```text
# Add the security context configuration.
type hdf_nnrt_device_service, hdf_service_attr;
```
3. Add the following configuration to the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/public/hdfdomain.te` file:
```text
# Add the security context configuration.
neverallow { domain -hdfdomain -sadomain } { hdfdomain -nnrt_host -allocator_host -hdf_public_domain }:binder call;
```
1. Configure the security context of the **nnrt_host** process in the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/vendor/type.te` file. 4. Add the following configuration to the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/public/type.te` file:
```text ```text
# Add the security context configuration. # Add the security context configuration.
type nnrt_host, hdfdomain, domain; type nnrt_host, hdfdomain, domain;
``` ```
> **NOTE**<br>In the preceding command, **nnrt_host** indicates the process name previously configured.
2. Configure access permissions because SELinux uses the trustlist access permission mechanism. Upon service startup, run the `dmesg` command to view the AVC alarm, 5. Add the following configuration to the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/vendor/hdf_devmgr.te` file:
which provides a list of missing permissions. For details about the SELinux configuration, see [security_selinux] (https://gitee.com/openharmony/security_selinux/blob/master/README-en.md). ```text
```shell # Add the security context configuration.
hdc_std shell allow hdf_devmgr nnrt_host:binder { call transfer };
dmesg | grep nnrt allow hdf_devmgr nnrt_host:dir { search };
allow hdf_devmgr nnrt_host:file { open read write };
allow hdf_devmgr nnrt_host:process { getattr };
```
6. Add the following configuration to the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/vendor/init.te` file:
```text
# Add the security context configuration.
allow init nnrt_host:process { rlimitinh siginh transition };
```
7. Modify the configuration in the `base/security/selinux/sepolicy/ohos_policy/startup/init/public/chipset_init.te` file.
Find the line containing `chipset_init`.
```text
allow chipset_init { light_host input_user_host wifi_host camera_host power_host audio_host }:process { rlimitinh siginh transition };
```
Add `nnrt_host` to the `host` list.
```text
allow chipset_init { light_host input_user_host wifi_host camera_host power_host audio_host nnrt_host }:process { rlimitinh siginh transition };
``` ```
3. Create the `nnrt_host.te` file. 8. Create the `nnrt_host.te` configuration file.
```shell ```shell
# Create the nnrt folder. # Create the nnrt folder.
mkdir base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt mkdir base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt
...@@ -292,28 +328,51 @@ which provides a list of missing permissions. For details about the SELinux conf ...@@ -292,28 +328,51 @@ which provides a list of missing permissions. For details about the SELinux conf
# Create the vendor folder. # Create the vendor folder.
mkdir base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt/vendor mkdir base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt/vendor
# Create the nnrt_host.te file. # Create the `nnrt_host.te` file.
touch base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt/vendor/nnrt_host.te touch base/security/selinux/sepolicy/ohos_policy/drivers/peripheral/nnrt/vendor/nnrt_host.te
``` ```
4. Add the required permissions to the `nnrt_host.te` file. For example: 9. Write the following required permissions to the `nnrt_host.te` file:
```text ```text
allow nnrt_host dev_hdf_kevent:chr_file { ioctl }; allow nnrt_host dev_hdf_kevent:chr_file { ioctl };
allow nnrt_host hilog_param:file { read }; allow nnrt_host hilog_param:file { read open map };
allow nnrt_host sh:binder { transfer }; allow nnrt_host sh:binder { transfer };
allow nnrt_host samgr:binder { call };
allow nnrt_host dev_ashmem_file:chr_file { open }; allow nnrt_host dev_ashmem_file:chr_file { open };
allow nnrt_host dev_unix_socket:dir { search };
allow nnrt_host hdf_device_manager:hdf_devmgr_class { get };
allow nnrt_host hdf_nnrt_device_service:hdf_devmgr_class { add get };
allow nnrt_host dev_console_file:chr_file { read write };
allow nnrt_host debug_param:file { read open map };
allow nnrt_host sa_device_service_manager:samgr_class { get };
allow nnrt_host hdf_devmgr:binder { call transfer };
allow nnrt_host hdf_nnrt_device_service:binder { call };
allow nnrt_host sysfs_devices_system_cpu:file { read open getattr };
allow sh hdf_nnrt_device_service:hdf_devmgr_class { add get };
allow sh hdf_hci_interface_service:hdf_devmgr_class { get };
allow sh nnrt_host:dir { getattr search };
allow sh nnrt_host:file { open read };
allow sh nnrt_host:process { getattr };
allow sh nnrt_host:binder { call };
allow sh nnrt_host:fd { use }; allow sh nnrt_host:fd { use };
``` ```
10. Configure access permissions because SELinux uses the trustlist access permission mechanism. Upon service startup, run the `dmesg` command to view the AVC alarm,
which provides a list of missing permissions. For details about the SELinux configuration, see [security_selinux] (https://gitee.com/openharmony/security_selinux/blob/master/README-en.md).
```shell
hdc_std shell
dmesg | grep nnrt
```
#### Configuring the Component Build Entry #### Configuring the Component Build Entry
Access the `chipset_common.json` file. Access the `chipset_common.json` file.
```shell ```shell
vim //productdefine/common/inherit/chipset_common.json vim //productdefine/common/inherit/chipset_common.json
``` ```
Add the following to `"subsystems"`, `"subsystem":"hdf"`, `"components"`: Add the following configuration to `"subsystems"`, `"subsystem":"hdf"`, and `"components"`:
```shell ```shell
{ {
"component": "drivers_peripheral_foo", "component": "drivers_peripheral_nnrt",
"features": [] "features": []
} }
``` ```
...@@ -329,27 +388,27 @@ rm -rf ./out ...@@ -329,27 +388,27 @@ rm -rf ./out
### Commissioning and Verification ### Commissioning and Verification
On completion of service development, you can use XTS to verify its basic functions and compatibility. On completion of service development, you can use XTS to verify its basic functions and compatibility. The operation procedure is as follows:
1. Build the **hats** test cases of NNRt in the `test/xts/hats/hdf/nnrt` directory. 1. Compile the **hats** test cases of NNRt in the `test/xts/hats/ai/nnrt/hdi` directory.
```shell ```shell
# Go to the hats directory. # Go to the hats directory.
cd test/xts/hats cd test/xts/hats
# Build the hats test cases. # Compile the `hats` test cases.
./build.sh suite=hats system_size=standard --product-name rk3568 ./build.sh suite=hats system_size=standard product_name=rk3568
# Return to the root directory. # Return to the root directory.
cd - cd -
``` ```
The hats test cases are exported to `out/rk3568/suites/hats/testcases/HatsHdfNnrtFunctionTest` in the relative code root directory. The test case executable file `HatsHdfNnrtFunctionTest` is exported to the `out/rk3568/suites/hats/testcases/` directory.
2. Push the test cases to the device. 2. Push the test case executable file to the `/data/local/tmp/` directory of the RK3568 device.
```shell ```shell
# Push the executable file of test cases to the device. In this example, the executable file is HatsHdfNnrtFunctionTest. # Push the test case executable file to the device. In this example, the executable file is HatsHdfNnrtFunctionTest.
hdc_std file send out/rk3568/suites/hats/testcases/HartsHdfNnrtFunctionTest /data/local/tmp/ hdc_std file send out/rk3568/suites/hats/testcases/HartsHdfNnrtFunctionTest /data/local/tmp/
# Grant required permissions to the executable file of test cases. # Grant required permissions to the test case executable file.
hdc_std shell "chmod +x /data/local/tmp/HatsHdfNnrtFunctionTest" hdc_std shell "chmod +x /data/local/tmp/HatsHdfNnrtFunctionTest"
``` ```
...@@ -359,7 +418,7 @@ On completion of service development, you can use XTS to verify its basic functi ...@@ -359,7 +418,7 @@ On completion of service development, you can use XTS to verify its basic functi
hdc_std shell "/data/local/tmp/HatsHdfNnrtFunctionTest" hdc_std shell "/data/local/tmp/HatsHdfNnrtFunctionTest"
``` ```
The test report below shows that all 47 test cases are successful, indicating that the service has passed the compatibility test. According to the following example test report, all of the 47 test cases are successfully executed, indicating the service has passed the compatibility test.
```text ```text
... ...
[----------] Global test environment tear-down [----------] Global test environment tear-down
...@@ -371,37 +430,40 @@ On completion of service development, you can use XTS to verify its basic functi ...@@ -371,37 +430,40 @@ On completion of service development, you can use XTS to verify its basic functi
### Development Example ### Development Example
For the complete demo code, see [NNRt Service Implementation Example](https://gitee.com/openharmony/ai_neural_network_runtime/tree/master/example/drivers). For the complete demo code, see [NNRt Service Implementation Example](https://gitee.com/openharmony/ai_neural_network_runtime/tree/master/example/drivers).
1. Copy the `example/driver/nnrt` directory to `drivers/peripheral`. 1. Go to the root directory of OpenHarmony source code and create the `nnrt` folder in the `drivers/peripheral` directory. Then, copy the `example/driver/nnrt/v2_0` folder from the `foundation/ai/neural_network_runtime` directory of NNRt source code to the created `nnrt` folder.
```shell ```shell
cp -r example/driver/nnrt drivers/peripheral cp -r example/drivers/nnrt/v2_0 drivers/peripheral/nnrt
``` ```
2. Add the `bundle.json` file to `drivers/peripheral/nnrt`. For details about the `bundle.json` file, see [Development Procedure](#development-procedure). 2. Add the `bundle.json` file to the `drivers/peripheral/nnrt` directory. For details about how to write the `bundle.json` file, see [Implementing the HDI Service](#implementing-the-hdi-service).
3. Add the dependency files of MindSpore Lite because the demo depends on the CPU operator of MindSpore Lite. 3. Add the dependency files of MindSpore Lite because the demo depends on the CPU operator of MindSpore Lite.
- Download the header file of [MindSpore Lite 1.5.0](https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.5.0/MindSpore/lite/release/linux/mindspore-lite-1.5.0-linux-x64.tar.gz). - Download the header file of [MindSpore Lite 1.8.1](https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.8.1/MindSpore/lite/release/android/gpu/mindspore-lite-1.8.1-android-aarch64.tar.gz).
1. Create the `mindspore` directory in `drivers/peripheral/nnrt`. - Create the `mindspore` folder in the `drivers/peripheral/nnrt/v2_0` directory to store the dynamic libraries and header files of MindSpore Lite.
```shell
mkdir drivers/peripheral/nnrt/v2_0/mindspore
```
- Decompress the `mindspore-lite-1.8.1-android-aarch64.tar.gz` file, and copy the `runtime/include` folder to the `drivers/peripheral/nnrt/v2_0/mindspore` directory.
```shell ```shell
mkdir drivers/peripheral/nnrt/mindspore cp mindspore-lite-1.8.1-android-aarch64/runtime/include drivers/peripheral/nnrt/v2_0/mindspore
``` ```
2. Decompress the `mindspore-lite-1.5.0-linux-x64.tar.gz` file, and copy the `runtime/include` directory to `drivers/peripheral/nnrt/mindspore`. - Create and copy the `schema` file of MindSpore Lite.
3. Create and copy the `schema` file of MindSpore Lite.
```shell ```shell
# Create the mindspore_schema directory. # Create the mindspore_schema folder.
mkdir drivers/peripheral/nnrt/hdi_cpu_service/include/mindspore_schema mkdir drivers/peripheral/nnrt/v2_0/hdi_cpu_service/include/mindspore_schema
# Copy the schema file of MindSpore Lite. # Copy the MindSpore schema file from the third_party directory.
cp third_party/mindspore/mindspore/lite/schema/* drivers/peripheral/nnrt/hdi_cpu_service/include/mindspore_schema/ cp third_party/mindspore/mindspore/lite/schema/* drivers/peripheral/nnrt/v2_0/hdi_cpu_service/include/mindspore_schema/
``` ```
4. Build the dynamic library of MindSpore Lite, and put the dynamic library in the `mindspore`directory. - Build the MindSpore Lite dynamic libraries of OpenHarmony, and copy them to the `mindspore` folder.
```shell ```shell
# Build the dynamic library of MindSpore Lite. # Build the MindSpore Lite dynamic libraries.
./build.sh --product-name rk3568 -ccaache --jobs 4 --build-target mindspore_lib ./build.sh --product-name rk3568 -ccaache --jobs 4 --build-target mindspore_lib
# Create the mindspore subdirectory. # Create the `mindspore` folder in the `drivers/peripheral/nnrt/v2_0/mindspore` directory.
mkdir drivers/peripheral/nnrt/mindspore/mindspore mkdir drivers/peripheral/nnrt/v2_0/mindspore/mindspore
# Copy the dynamic library to drivers/peripheral/nnrt/mindspore/mindspore. # Copy the MindSpore dynamic libraries from the `out` folder to the `drivers/peripheral/nnrt/v2_0/mindspore/mindspore` directory.
cp out/rk3568/package/phone/system/lib/libmindspore-lite.huawei.so drivers/peripheral/nnrt/mindspore/mindspore/ cp out/rk3568/package/phone/system/lib/libmindspore-lite.huawei.so drivers/peripheral/nnrt/v2_0/mindspore/mindspore/
``` ```
4. Follow the [development procedure](#development-procedure) to complete other configurations. 4. Follow the [development procedure](#development-procedure) to complete other configurations.
...@@ -223,7 +223,7 @@ The following is a demo debugging process, where the **StartTrace** and **Finish ...@@ -223,7 +223,7 @@ The following is a demo debugging process, where the **StartTrace** and **Finish
external_deps = [ "hitrace:hitrace_meter" ] external_deps = [ "hitrace:hitrace_meter" ]
subsystem_name = "hiviewdfx" subsystem_name = "hiviewdfx"
part_name = "hitrace" part_name = "hitrace_native"
} }
group("hitrace_target") { group("hitrace_target") {
......
...@@ -88,7 +88,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -88,7 +88,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
"subsystem": "product_hihope" "subsystem": "product_hihope"
} }
``` ```
In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_hdf_config` is the build target. In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_service_config` is the build target.
6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
......
...@@ -106,7 +106,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -106,7 +106,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
"subsystem": "product_hihope" "subsystem": "product_hihope"
} }
``` ```
In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_hdf_config` is the build target. In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_service_config` is the build target.
6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
...@@ -150,7 +150,6 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -150,7 +150,6 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
``` ```
## Reference ## Reference
During development, you can refer to the [default thermal control configuration](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml). During development, you can refer to the [default thermal control configuration](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml).
Packing path: `/vendor/etc/thermal_config/hdf` Packing path: `/vendor/etc/thermal_config/hdf`
...@@ -144,6 +144,6 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -144,6 +144,6 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
``` ```
## Reference ## Reference
During development, you can refer to the [default thermal detection configuration](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/thermal_hdi_config.xml). During development, you can refer to the [default thermal detection configuration](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile/thermal_hdf_config.xml).
Packing path: `/vendor/etc/thermal_config/hdf` Packing path: `/vendor/etc/thermal_config/hdf`
...@@ -111,7 +111,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -111,7 +111,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
"subsystem": "product_hihope" "subsystem": "product_hihope"
} }
``` ```
In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_hdf_config` is the build target. In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_service_config` is the build target.
6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
......
...@@ -26,7 +26,7 @@ For details about the requirements on the Linux environment, see [Quick Start](. ...@@ -26,7 +26,7 @@ For details about the requirements on the Linux environment, see [Quick Start](.
The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate thermal log customization. The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate thermal log customization.
1. Create the thermal folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568). 1. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
2. Create a target folder by referring to the [default thermal log configuration folder](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows: 2. Create a target folder by referring to the [default thermal log configuration folder](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows:
...@@ -50,6 +50,8 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -50,6 +50,8 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
| Configuration Item| Description| Data Type| Value Range| | Configuration Item| Description| Data Type| Value Range|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| interval | Interval for recording temperature tracing logs, in ms.| int | >0 |
| width | Width of the temperature tracing log, in characters.| int | >0 |
| outpath | Path for storing temperature tracing logs.| string | N/A| | outpath | Path for storing temperature tracing logs.| string | N/A|
**Table 2** Description of the node configuration **Table 2** Description of the node configuration
...@@ -61,7 +63,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -61,7 +63,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
| value | path | Path for obtaining the thermal zone temperature.| | value | path | Path for obtaining the thermal zone temperature.|
```shell ```shell
<tracing outpath="/data/log/thermal-log"> <tracing interval="5000" width="20" outpath="/data/log/thermal-log">
<node> <node>
<title path="sys/class/thermal/thermal_zone0/type"/> <title path="sys/class/thermal/thermal_zone0/type"/>
<value path="sys/class/thermal/thermal_zone0/temp"/> <value path="sys/class/thermal/thermal_zone0/temp"/>
...@@ -84,10 +86,10 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -84,10 +86,10 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
thermal.para.dac: thermal.para.dac:
```text ```text
persist.thermal.log.="power_host:power_host:500" # Configure access permissions. persist.thermal.log.="power_host:power_host:600" # Configure access permissions.
``` ```
6. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn) file in the default thermal log configuration folder to pack the thermal_hdi_config.xml file to the `//vendor/etc/thermal_config/hdf` directory. The configuration is as follows: 6. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn) file in the default thermal log configuration folder to pack the `thermal_hdi_config.xml` file to the `//vendor/etc/thermal_config/hdf` directory. The configuration is as follows:
```shell ```shell
import("//build/ohos.gni") import("//build/ohos.gni")
...@@ -95,7 +97,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -95,7 +97,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
ohos_prebuilt_etc("thermal_hdf_config") { ohos_prebuilt_etc("thermal_hdf_config") {
source = "thermal_hdi_config.xml" source = "thermal_hdi_config.xml"
relative_install_dir = "thermal_config/hdf" relative_install_dir = "thermal_config/hdf"
install_images = [ chipset_base_dir ] # Required configuration for installing the thermal_service_config.xml file in the vendor directory. install_images = [ chipset_base_dir ] # Required configuration for installing the thermal_hdi_config.xml file in the vendor directory.
part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. You can change it as required. part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. You can change it as required.
} }
``` ```
...@@ -149,7 +151,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -149,7 +151,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
"subsystem": "product_hihope" "subsystem": "product_hihope"
} }
``` ```
In the preceding code, //vendor/hihope/rk3568/thermal/ is the folder path, profile and etc are folder names, and thermal_hdf_config and param_files are the build targets. In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` and `etc` are folder names, and `thermal_hdf_config` and `param_files` are the build targets.
9. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 9. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
......
...@@ -150,7 +150,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -150,7 +150,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
"subsystem": "product_hihope" "subsystem": "product_hihope"
} }
``` ```
In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_hdf_config` is the build target. In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_service_config` is the build target.
6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
......
...@@ -86,7 +86,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ...@@ -86,7 +86,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma
"subsystem": "product_hihope" "subsystem": "product_hihope"
} }
``` ```
In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_hdf_config` is the build target. In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_service_config` is the build target.
6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册