diff --git a/en/application-dev/connectivity/socket-connection.md b/en/application-dev/connectivity/socket-connection.md index 109b63fdb5fdcae98e23882b32018d4a03435f55..9dda8b4e4c0ac6931ea75ad706fef76c9fb3c0a3 100644 --- a/en/application-dev/connectivity/socket-connection.md +++ b/en/application-dev/connectivity/socket-connection.md @@ -2,7 +2,7 @@ ## 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 @@ -13,10 +13,11 @@ The Socket Connection module allows an application to transmit data over a Socke ## 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 encrypted data transmission over TLS Socket connections +- Implementing data transmission over TCP socket or UDP socket connections +- Implementing data transmission over TCP socket server connections +- Implementing encrypted data transmission over TLS socket connections ## Available APIs @@ -28,72 +29,75 @@ Socket connection functions are mainly implemented by the **socket** module. The | -------- | -------- | | constructUDPSocketInstance() | Creates a **UDPSocket** 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.| | send() | Sends data.| -| close() | Closes a Socket connection.| -| getState() | Obtains the Socket connection status.| +| close() | Closes a socket connection.| +| getState() | Obtains the socket connection status.| | 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.| -| on(type: 'message') | Subscribes to **message** events of the Socket connection.| -| off(type: 'message') | Unsubscribes from **message** events of the Socket connection.| -| on(type: 'close') | Subscribes to **close** events of the Socket connection.| -| off(type: 'close') | Unsubscribes from **close** events of the Socket connection.| -| on(type: 'error') | Subscribes to **error** events of the Socket connection.| -| off(type: 'error') | Unsubscribes from **error** events of the Socket connection.| -| on(type: 'listening') | Subscribes to **listening** events of the UDP Socket connection. | -| off(type: 'listening') | Unsubscribes from **listening** events of the UDP Socket connection. | -| on(type: 'connect') | Subscribes to **connect** events of the TCP Socket connection. | -| off(type: '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. +| 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.| +| setExtraOptions() | Sets other properties of the socket connection.| +| on(type: 'message') | Subscribes to **message** events of the socket connection.| +| off(type: 'message') | Unsubscribes from **message** events of the socket connection.| +| on(type: 'close') | Subscribes to **close** events of the socket connection.| +| off(type: 'close') | Unsubscribes from **close** events of the socket connection.| +| on(type: 'error') | Subscribes to **error** events of the socket connection.| +| off(type: 'error') | Unsubscribes from **error** events of the socket connection.| +| on(type: 'listening') | Subscribes to **listening** events of the UDP socket connection. | +| off(type: 'listening') | Unsubscribes from **listening** events of the UDP socket connection. | +| on(type: 'connect') | Subscribes to **connect** events of the TCP socket connection. | +| off(type: '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. | API| Description| | -------- | -------- | | constructTLSSocketInstance() | Creates a **TLSSocket** object.| | bind() | Binds the IP address and port number.| -| close(type: 'error') | Closes a Socket connection.| +| close(type: 'error') | Closes a socket connection.| | connect() | Sets up a connection to the specified IP address and port number.| | getCertificate() | Obtains an object representing the local certificate.| | 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.| -| 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.| | 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.| -| off(type: 'close') | Unsubscribes from **close** events of the TLS Socket connection.| -| off(type: 'error') | Unsubscribes from **error** events of the TLS Socket connection.| -| off(type: 'message') | Unsubscribes from **message** events of the TLS Socket connection.| -| on(type: 'close') | Subscribes to **close** events of the TLS Socket connection.| -| on(type: 'error') | Subscribes to **error** events of the TLS Socket connection.| -| on(type: 'message') | Subscribes to **message** events of the TLS Socket connection.| +| getState() | Obtains the TLS socket connection status.| +| off(type: 'close') | Unsubscribes from **close** events of the TLS socket connection.| +| off(type: 'error') | Unsubscribes from **error** events of the TLS socket connection.| +| off(type: 'message') | Unsubscribes from **message** events of the TLS socket connection.| +| on(type: 'close') | Subscribes to **close** events of the TLS socket connection.| +| on(type: 'error') | Subscribes to **error** events of the TLS socket connection.| +| on(type: 'message') | Subscribes to **message** events of the TLS socket connection.| | 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. -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. 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 import socket from '@ohos.net.socket' -// Create a TCPSocket object. +// Create a TCP socket connection. A TCPSocket object is returned. let tcp = socket.constructTCPSocketInstance(); -// Subscribe to TCP Socket connection events. +// Subscribe to events of the TCPSocket object. tcp.on('message', value => { console.log("on message") let buffer = value.message @@ -139,7 +143,7 @@ tcp.bind(bindAddress, err => { } console.log('connect success'); - // Send data. + // Send data over the connection. tcp.send({ data: 'Hello, server!' }, 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(() => { tcp.close((err) => { console.log('close socket.') @@ -163,11 +167,92 @@ setTimeout(() => { }, 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 ### 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. @@ -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. -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 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(); -// Subscribe to TLS Socket connection events. +// Subscribe to TLS socket connection events. tlsTwoWay.on('message', value => { console.log("on message") let buffer = value.message @@ -246,7 +331,7 @@ tlsTwoWay.connect(options, (err, 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) => { if (err) { console.log("close callback error = " + err); @@ -258,10 +343,10 @@ tlsTwoWay.close((err) => { 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 -// Subscribe to TLS Socket connection events. +// Subscribe to TLS socket connection events. tlsTwoWay.on('message', value => { console.log("on message") let buffer = value.message @@ -307,7 +392,7 @@ tlsOneWay.connect(oneWayOptions, (err, 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) => { if (err) { console.log("close callback error = " + err); @@ -319,11 +404,3 @@ tlsTwoWay.close((err) => { 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) diff --git a/en/application-dev/reference/apis/js-apis-intl.md b/en/application-dev/reference/apis/js-apis-intl.md index 99131363c58faef8abe196d0e20e01b176a1258e..57a49408d7da9e24242b879b6bf902c53606216b 100644 --- a/en/application-dev/reference/apis/js-apis-intl.md +++ b/en/application-dev/reference/apis/js-apis-intl.md @@ -14,7 +14,6 @@ The [i18n](js-apis-i18n.md) module provides enhanced i18n capabilities through s ```js import Intl from '@ohos.intl'; ``` -Importing an incorrect bundle can lead to unexpected API behavior. ## Locale @@ -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**.| | 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**.| -| 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**. | ### constructor8+ @@ -67,7 +66,7 @@ Creates a **Locale** object. | 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).| -| options | [LocaleOptions](#localeoptions6) | No | Options for creating the **Locale** object. | +| options | [LocaleOptions](#localeoptions6) | No | Options for creating the **Locale** object.| **Example** ```js @@ -162,7 +161,7 @@ Minimizes information of the **Locale** object. If the script and locale informa ## LocaleOptions6+ 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 @@ -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**.| | 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**.| -| 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**.| @@ -207,7 +206,7 @@ Creates a **DateTimeOptions** object for the specified locale. | Name | Type | Mandatory | Description | | -------------------- | ------------------------------------ | ---- | ---------------------------- | | locale | string \| Array<string> | 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** ```js @@ -314,7 +313,7 @@ Obtains the formatting options for **DateTimeFormat** object. ## DateTimeOptions6+ 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 @@ -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**.| | 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**.| -| 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**.| | 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**. | @@ -438,31 +437,31 @@ Obtains the options of the **NumberFormat** object. ## NumberOptions6+ 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 | 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**. | -| currencySign | string | Yes | Yes | Currency unit symbol. 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**.| +| 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**. The default value is **symbol**.| | 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**.| -| unitUsage8+ | 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**.| -| signDisplay | string | Yes | Yes | Number sign display format. The value can be **auto**, **never**, **always**, or **expectZero**.| -| compactDisplay | string | Yes | Yes | Compact display format. The value can be **long** or **short**. | -| notation | string | Yes | Yes | Number formatting specification. The value can be **standard**, **scientific**, **engineering**, or **compact**.| -| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.| -| style | string | Yes | Yes | Number display format. The value can be **decimal**, **currency**, **percent**, or **unit**.| -| 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**.| -| useGrouping | boolean | Yes | Yes | Whether to use grouping for display. | -| minimumIntegerDigits | number | Yes | Yes | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. | -| minimumFractionDigits | number | Yes | Yes | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. | -| maximumFractionDigits | number | Yes | Yes | Maximum number of digits in the fraction part of a number. 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**. | -| maximumSignificantDigits | number | Yes | Yes | Maximum number of the least significant digits. The value ranges from **1** to **21**. | +| unitDisplay | string | Yes | Yes | Unit display format. The value can be **long**, **short**, or **narrow**. The default value is **short**.| +| unitUsage8+ | 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**. The default value is **auto**.| +| 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**. The default value is **standard**.| +| 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**. 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**. The default value is the default numbering system of the specified locale.| +| 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**. 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**. 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**. The default value is **3**. | +| 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**. The default value is **21**. | ## Collator8+ @@ -496,7 +495,7 @@ Creates a **Collator** object. | Name | Type | Mandatory | Description | | -------------------- | ------------------------------------ | ---- | ---------------------------- | | locale | string \| Array<string> | 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** ```js @@ -562,19 +561,19 @@ Returns properties reflecting the locale and collation options of a **Collator** ## CollatorOptions8+ 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 | Name | Type | Readable | Writable | Description | | ----------------- | ------- | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.| -| usage | string | Yes | Yes | Whether the comparison is for sorting or for searching. The value can be **sort** or **search**. | -| sensitivity | string | Yes | Yes | Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **letiant**.| -| ignorePunctuation | boolean | Yes | Yes | Whether punctuation is ignored. The value can be **true** or **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**.| -| numeric | boolean | Yes | Yes | Whether numeric collation is used. The value can be **true** or **false**. | -| caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.| +| 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**. 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**. The default value is **variant**.| +| 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**. The default value is **default**.| +| 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**. The default value is **false**.| ## PluralRules8+ @@ -608,7 +607,7 @@ Creates a **PluralRules** object to obtain the singular-plural type of numbers. | Name | Type | Mandatory | Description | | -------------------- | ---------------------------------------- | ---- | ---------------------------- | | locale | string \| Array<string> | 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** ```js @@ -654,19 +653,19 @@ Obtains a string that represents the singular-plural type of the specified numbe ## PluralRulesOptions8+ 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 | Name | Type | Readable | Writable | Description | | ------------------------ | ------ | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.| -| type | string | Yes | Yes | Sorting type. The value can be **cardinal** or **ordinal**. | -| minimumIntegerDigits | number | Yes | Yes | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. | -| minimumFractionDigits | number | Yes | Yes | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. | -| maximumFractionDigits | number | Yes | Yes | Maximum number of digits in the fraction part of a number. 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**. | -| maximumSignificantDigits | number | Yes | Yes | Maximum number of the least significant digits. The value ranges from **1** to **21**. | +| 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**. 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**. 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**. 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**. The default value is **3**. | +| 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**. The default value is **21**. | ## RelativeTimeFormat8+ @@ -795,15 +794,14 @@ Obtains the formatting options for **RelativeTimeFormat** objects. ## RelativeTimeFormatInputOptions8+ 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 - | Name | Type | Readable | Writable | Description | | ------------- | ------ | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.| -| numeric | string | Yes | Yes | Format of the output message. The value can be **always** or **auto**. | -| style | string | Yes | Yes | Length of an internationalized message. The value can be **long**, **short**, or **narrow**.| +| 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**. The default value is **always**. | +| style | string | Yes | Yes | Length of an internationalized message. The value can be **long**, **short**, or **narrow**. The default value is **long**.| ## RelativeTimeFormatResolvedOptions8+ diff --git a/en/application-dev/reference/apis/js-apis-mindSporeLite.md b/en/application-dev/reference/apis/js-apis-mindSporeLite.md index 6a80afa3976c1ee8c4fdce9e3ffa0e1288fdd62c..715e85272a6ee38728f675d0ac6c13eb388631f2 100644 --- a/en/application-dev/reference/apis/js-apis-mindSporeLite.md +++ b/en/application-dev/reference/apis/js-apis-mindSporeLite.md @@ -1,7 +1,7 @@ # @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. -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** > @@ -48,7 +48,7 @@ Defines the CPU backend device option. | 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**.| | 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. @@ -125,7 +125,7 @@ Loads the input model from the full path for model inference. This API uses an a ```js let context: mindSporeLite.Context = {}; -let context = {'target': ['cpu']}; +context = {'target': ['cpu']}; let model_file = '/path/to/xxx.ms'; mindSporeLite.loadModelFromFile(model_file, context, (result) => { const modelInputs = result.getInputs(); @@ -181,17 +181,17 @@ Loads the input model from the memory for inference. This API uses an asynchrono ```js import resourceManager from '@ohos.resourceManager' -@State modelName: string = 'xxx.ms'; +let modelName = '/path/to/xxx.ms'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.modelName).then((buffer) => { - this.modelBuffer = buffer; +syscontext.resourceManager.getRawFileContent(modelName).then((buffer) => { + let modelBuffer = buffer; + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer, (result) => { + const modelInputs = result.getInputs(); + console.log(modelInputs[0].name); + }) }).catch(error => { 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 @@ -213,19 +213,19 @@ Loads the input model from the memory for inference. This API uses an asynchrono ```js import resourceManager from '@ohos.resourceManager' -@State modelName: string = 'xxx.ms'; +let modelName = '/path/to/xxx.ms'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.modelName).then((error,buffer) => { - this.modelBuffer = buffer; +syscontext.resourceManager.getRawFileContent(modelName).then((error,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 => { 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 @@ -252,17 +252,17 @@ Loads the input model from the memory for inference. This API uses a promise to ```js import resourceManager from '@ohos.resourceManager' -@State modelName: string = 'xxx.ms'; +let modelName = '/path/to/xxx.ms'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.modelName).then((buffer) => { - this.modelBuffer = buffer; +syscontext.resourceManager.getRawFileContent(modelName).then((buffer) => { + let modelBuffer = buffer; + mindSporeLite.loadModelFromBuffer(modelBuffer.buffer).then((result) => { + const modelInputs = result.getInputs(); + console.log(modelInputs[0].name); + }) }).catch(error => { 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 @@ -284,7 +284,7 @@ Loads the input model based on the specified file descriptor for inference. This ```js import fs from '@ohos.file.fs'; 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) => { const modelInputs = result.getInputs(); console.log(modelInputs[0].name); @@ -313,7 +313,7 @@ import fs from '@ohos.file.fs'; let model_file = '/path/to/xxx.ms'; let context : mindSporeLite.Context = {}; 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) => { const modelInputs = result.getInputs(); console.log(modelInputs[0].name); @@ -345,7 +345,7 @@ Loads the input model based on the specified file descriptor for inference. This ```js import fs from '@ohos.file.fs'; 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); mindSporeLite.loadModelFromFd(file.fd).then((result) => { const modelInputs = result.getInputs(); @@ -383,9 +383,9 @@ mindSporeLite.loadModelFromFile(model_file).then((result) => { ``` ### predict -predict(inputs: MSTensor[], callback: Callback<Model>): void +predict(inputs: MSTensor[], callback: Callback<MSTensor[]>): 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 @@ -394,20 +394,20 @@ Executes the inference model. This API uses an asynchronous callback to return t | Name| Type | Mandatory| Description | | ------ | ----------------------- | ---- | -------------------------- | | 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** ```js import resourceManager from '@ohos.resourceManager' -@State inputName: string = 'input_data.bin'; +let inputName = 'input_data.bin'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { - this.inputBuffer = buffer; +syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { + let 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); + modelInputs[0].setData(inputBuffer.buffer); result.predict(modelInputs, (result) => { let output = new Float32Array(result[0].getData()); for (let i = 0; i < output.length; i++) { @@ -420,7 +420,7 @@ syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { predict(inputs: MSTensor[]): Promise<MSTensor[]> -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 @@ -440,14 +440,14 @@ Executes the inference model. This API uses a promise to return the result. ```js import resourceManager from '@ohos.resourceManager' -@State inputName: string = 'input_data.bin'; +let inputName = 'input_data.bin'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { - this.inputBuffer = buffer; +syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { + let 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); + modelInputs[0].setData(inputBuffer.buffer); result.predict(modelInputs).then((result) => { let output = new Float32Array(result[0].getData()); for (let i = 0; i < output.length; i++) { @@ -541,14 +541,14 @@ Obtains tensor data. ```js import resourceManager from '@ohos.resourceManager' -@State inputName: string = 'input_data.bin'; +let inputName = 'input_data.bin'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { - this.inputBuffer = buffer; +syscontext.resourceManager.getRawFileContent(inputName).then(async (buffer) => { + let 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); + modelInputs[0].setData(inputBuffer.buffer); result.predict(modelInputs).then((result) => { let output = new Float32Array(result[0].getData()); for (let i = 0; i < output.length; i++) { @@ -576,15 +576,15 @@ Sets the tensor data. ```js import resourceManager from '@ohos.resourceManager' -@State inputName: string = 'input_data.bin'; +let inputName = 'input_data.bin'; let syscontext = globalThis.context; -syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { - this.inputBuffer = buffer; +syscontext.resourceManager.getRawFileContent(inputName).then(async (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 diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md index 406339fa52423ebf5b29d83f9933b47280ea7b9d..40cb3dc087b7b7a756a602925699597ec557c294 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -35,10 +35,10 @@ getResourceManager(callback: AsyncCallback<ResourceManager>): void 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 +**Model restriction**: This API can be used only in the FA model. + **Parameters** | Name | Type | Mandatory | Description | @@ -52,7 +52,7 @@ Obtains the **ResourceManager** object of this application. This API uses an asy console.log("error is " + error); return; } - mgr.getString(0x1000000, (error, value) => { + mgr.getStringValue(0x1000000, (error, value) => { if (error != null) { console.log("error is " + error); } else { @@ -70,10 +70,10 @@ getResourceManager(bundleName: string, callback: AsyncCallback<ResourceManage 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 +**Model restriction**: This API can be used only in the FA model. + **Parameters** | Name | Type | Mandatory | Description | @@ -94,10 +94,10 @@ getResourceManager(): Promise<ResourceManager> 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 +**Model restriction**: This API can be used only in the FA model. + **Return value** | Type | Description | @@ -107,7 +107,7 @@ Obtains the **ResourceManager** object of this application. This API uses a prom **Example** ```js resourceManager.getResourceManager().then(mgr => { - mgr.getString(0x1000000, (error, value) => { + mgr.getStringValue(0x1000000, (error, value) => { if (error != null) { console.log("error is " + error); } else { @@ -127,10 +127,10 @@ getResourceManager(bundleName: string): Promise<ResourceManager> 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 +**Model restriction**: This API can be used only in the FA model. + **Parameters** | Name | Type | Mandatory | Description | @@ -185,7 +185,7 @@ try { console.log("systemResourceManager getStringValue promise error is " + 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. | direction | [Direction](#direction) | Yes | No | Screen direction of the device.| | 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 @@ -271,16 +261,6 @@ Defines the device capability. | screenDensity | [ScreenDensity](#screendensity) | Yes | No | Screen density 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; - }); - }); - ``` ## RawFileDescriptor8+ @@ -357,7 +337,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 console.log("getStringValue promise error is " + 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -447,7 +429,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -497,7 +481,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco console.log("getStringValue promise error is " + 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 } }); } 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 console.log("getStringArrayValue promise error is " + 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -627,7 +613,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -675,7 +663,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco console.log("getStringArray promise error is " + 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 } }); } 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 } }); } 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 console.log("getMediaContent promise error is " + 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 console.error(`promise getMediaContent failed, error code: ${error.code}, message: ${error.message}.`); }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -883,7 +873,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -928,7 +920,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -975,7 +969,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco console.log("getMediaContent promise error is " + 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -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}.`); }); } 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 } }); } 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 } }); } 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 console.log("getMediaContentBase64 promise error is " + 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 console.error(`promise getMediaContentBase64 failed, error code: ${error.code}, message: ${error.message}.`); }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -1231,7 +1229,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -1270,13 +1270,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getMediaContentBase64(resource, 120, (error, value) => { 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 { let media = value; } }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -1323,7 +1325,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco console.log("getMediaContentBase64 promise error is " + 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -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}.`); }); } 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 **Example** ```ts - resourceManager.getResourceManager((error, mgr) => { - mgr.getConfiguration((error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let direction = value.direction; - let locale = value.locale; - } - }); - }); + try { + this.context.resourceManager.getConfiguration((error, value) => { + if (error != null) { + console.error("getConfiguration callback error is " + error); + } else { + let direction = value.direction; + 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. **Example** ```ts - resourceManager.getResourceManager((error, mgr) => { - mgr.getConfiguration().then(value => { - let direction = value.direction; - let locale = value.locale; - }).catch(error => { - console.log("getConfiguration promise error is " + error); - }); - }); + try { + this.context.resourceManager.getConfiguration().then(value => { + let direction = value.direction; + let locale = value.locale; + }).catch(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 **Example** ```ts - resourceManager.getResourceManager((error, mgr) => { - mgr.getDeviceCapability((error, value) => { - if (error != null) { - console.log("error is " + error); - } else { - let screenDensity = value.screenDensity; - let deviceType = value.deviceType; - } - }); - }); + try { + this.context.resourceManager.getDeviceCapability((error, value) => { + if (error != null) { + console.error("getDeviceCapability callback error is " + error); + } else { + let screenDensity = value.screenDensity; + 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. **Example** ```ts - resourceManager.getResourceManager((error, mgr) => { - mgr.getDeviceCapability().then(value => { - let screenDensity = value.screenDensity; - let deviceType = value.deviceType; - }).catch(error => { - console.log("getDeviceCapability promise error is " + error); - }); - }); + try { + this.context.resourceManager.getDeviceCapability().then(value => { + let screenDensity = value.screenDensity; + let deviceType = value.deviceType; + }).catch(error => { + console.error("getDeviceCapability promise error is " + error); + }); + } catch (error) { + console.error("getDeviceCapability promise error is " + error); + } ``` - ### getPluralStringValue9+ getPluralStringValue(resId: number, num: number, callback: AsyncCallback<string>): void @@ -1524,8 +1535,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 console.log("getPluralStringValue promise error is " + 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}.`); + } ``` ### getPluralStringValue9+ @@ -1581,6 +1592,8 @@ Obtains the singular-plural string corresponding to the specified resource objec **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -1615,9 +1628,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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}.`); + } ``` ### getPluralStringValue9+ @@ -1628,6 +1640,8 @@ Obtains the singular-plural string corresponding to the specified resource objec **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -1665,7 +1679,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco console.log("getPluralStringValue promise error is " + 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 } }); } 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}.`); } - ``` ### getRawFileContent9+ @@ -1746,7 +1759,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco console.log("getRawFileContent promise error is " + 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 } }); } 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}.`); + } ``` ### getRawFd9+ @@ -1831,7 +1844,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco }); } catch (error) { console.error(`promise getRawFd failed, error code: ${error.code}, message: ${error.message}.`); - }; + } ``` ### getRawFileList10+ @@ -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. this.context.resourceManager.getRawFileList("", (error, value) => { 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 { let rawFile = value; } }); } 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}.`); } - ``` ### getRawFileList10+ @@ -1907,71 +1919,13 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco this.context.resourceManager.getRawFileList("").then(value => { let rawFile = value; }).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) { - console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`) + console.error(`promise getRawFileList failed, error code: ${error.code}, message: ${error.message}.`); } ``` -### closeRawFileDescriptor8+ - -closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): 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<void> | 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); - } - }); - }); - ``` - -### closeRawFileDescriptor8+ - -closeRawFileDescriptor(path: string): Promise<void> - -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<void> | 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); - }); - }); - ``` - - ### closeRawFd9+ closeRawFd(path: string, callback: AsyncCallback<void>): void @@ -2004,7 +1958,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 console.log("closeRawFd promise error is " + 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. **Example** ```ts - resourceManager.getResourceManager((error, mgr) => { - mgr.release(); - }); + try { + this.context.resourceManager.release(); + } catch (error) { + console.error("release error is " + error); + } ``` ### getStringByName9+ @@ -2101,9 +2057,8 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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}.`); } - ``` ### getStringByName9+ @@ -2145,7 +2100,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco console.log("getStringByName promise error is " + 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 } }); } 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 console.log("getStringArrayByName promise error is " + 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 } }); } 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 } }); } 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 console.error(`promise getMediaByName failed, error code: ${error.code}, message: ${error.message}.`); }); } 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 } }); } 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 } }); } 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 console.log("getMediaBase64ByName promise error is " + 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 console.error(`promise getMediaBase64ByName failed, error code: ${error.code}, message: ${error.message}.`); }); } 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 } }); } 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 console.log("getPluralStringByName promise error is " + 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 try { this.context.resourceManager.getStringSync($r('app.string.test').id); } 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 try { this.context.resourceManager.getStringSync($r('app.string.test').id, "format string", 10, 98.78); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -2766,7 +2723,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getStringSync(resource); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -2812,7 +2771,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getStringSync(resource, "format string", 10, 98.78); } 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 try { this.context.resourceManager.getStringByNameSync("test"); } 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 try { this.context.resourceManager.getStringByNameSync("test", "format string", 10, 98.78); } 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 try { this.context.resourceManager.getBoolean($r('app.boolean.boolean_test').id); } catch (error) { - console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`) + console.error(`getBoolean failed, error code: ${error.code}, message: ${error.message}.`); } ``` ### getBoolean9+ @@ -2942,6 +2901,8 @@ Obtains the Boolean result corresponding to the specified resource object. This **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -2974,7 +2935,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getBoolean(resource); } 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 try { this.context.resourceManager.getBooleanByName("boolean_test"); } 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 try { this.context.resourceManager.getNumber($r('app.integer.integer_test').id); // integer refers to the original value. } 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 { this.context.resourceManager.getNumber($r('app.float.float_test').id); // float refers to the actual pixel value. } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -3102,7 +3065,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getNumber(resource);// integer refers to the original value; float refers to the actual pixel value. } 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 try { this.context.resourceManager.getNumberByName("integer_test"); } 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 { this.context.resourceManager.getNumberByName("float_test"); } 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 try { this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id); } 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 { this.context.resourceManager.getDrawableDescriptor($r('app.media.icon').id, 120); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -3235,12 +3200,12 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getDrawableDescriptor(resource); } 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 { this.context.resourceManager.getDrawableDescriptor(resource, 120); } 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 try { this.context.resourceManager.getDrawableDescriptorByName('icon'); } 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 { this.context.resourceManager.getDrawableDescriptorByName('icon', 120); } 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 } }); } 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 console.log("getColor promise error is " + 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -3412,7 +3379,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } }); } 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 **System capability**: SystemCapability.Global.ResourceManager +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -3460,7 +3429,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco console.log("getColor promise error is " + 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 } }); } 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 console.log("getColorByName promise error is " + 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 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 @@ -3582,7 +3551,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getColorSync($r('app.color.test').id); } 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 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 +**Model restriction**: This API can be used only in the stage model. + **Parameters** | Name | Type | Mandatory | Description | @@ -3626,7 +3597,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getColorSync(resource); } 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 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 @@ -3665,7 +3636,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.context.resourceManager.getColorByNameSync("test"); } 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 try { this.context.resourceManager.addResource(path); } catch (error) { - console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`) - } + console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`); + } ``` ### removeResource10+ @@ -3729,7 +3700,7 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco try { this.resmgr.removeResource(path); } 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 }); }); ``` + +### closeRawFileDescriptor(deprecated) + +closeRawFileDescriptor(path: string, callback: AsyncCallback<void>): 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<void> | 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(deprecated) + +closeRawFileDescriptor(path: string): Promise<void> + +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<void> | 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); + }); + }); + ``` diff --git a/en/application-dev/reference/apis/js-apis-runninglock.md b/en/application-dev/reference/apis/js-apis-runninglock.md index 4d72733c02f607fd17f29f2c4402f059bfee981f..b922bf8e507bb1fd219097870e1520e00ba04224 100644 --- a/en/application-dev/reference/apis/js-apis-runninglock.md +++ b/en/application-dev/reference/apis/js-apis-runninglock.md @@ -16,7 +16,7 @@ import runningLock from '@ohos.runningLock'; 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 @@ -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.| -**Return Value** +**Return value** | Type | Description | | ------- | --------------------------------------- | @@ -69,14 +69,6 @@ Creates a **RunningLock** object. | 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.| -**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** ```js @@ -106,20 +98,12 @@ Creates a **RunningLock** object. | name | string | Yes | Name of the **RunningLock** object. | | type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object to be created.| -**Return Value** +**Return value** | Type | Description | | ------------------------------------------ | ------------------------------------ | | Promise<[RunningLock](#runninglock)> | 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** ```js @@ -138,7 +122,7 @@ isRunningLockTypeSupported(type: RunningLockType, callback: AsyncCallback<boo > **NOTE**
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 @@ -167,7 +151,7 @@ isRunningLockTypeSupported(type: RunningLockType): Promise<boolean> > **NOTE**
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 @@ -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.| -**Return Value** +**Return value** | Type | Description | | ---------------------- | ---------------------------------------------------- | @@ -246,7 +230,7 @@ Creates a **RunningLock** object. | name | string | Yes | Name of the **RunningLock** object. | | type | [RunningLockType](#runninglocktype) | Yes | Type of the **RunningLock** object to be created.| -**Return Value** +**Return value** | Type | Description | | ------------------------------------------ | ------------------------------------ | @@ -354,7 +338,7 @@ Checks the hold status of the **Runninglock** object. **System capability:** SystemCapability.PowerManager.PowerManager.Core -**Return Value** +**Return value** | Type | Description | | ------- | ------------------------------------------------------------ | @@ -452,7 +436,7 @@ Checks the hold status of the **Runninglock** object. **System capability:** SystemCapability.PowerManager.PowerManager.Core -**Return Value** +**Return value** | Type | Description | | ------- | ------------------------------------------------------------ | | 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. | Name | Value | Description | | --------------------------------- | ---- | ------------------------------------------------------------ | -| BACKGROUND(deprecated) | 1 | A lock that prevents the system from hibernating when the screen is off.
**NOTE**
This parameter is supported since API version 7 and deprecated since API version 10.| +| BACKGROUND(deprecated) | 1 | A lock that prevents the system from hibernating when the screen is off.
**NOTE**
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. | diff --git a/en/application-dev/reference/apis/js-apis-socket.md b/en/application-dev/reference/apis/js-apis-socket.md index f7d978eb79961eec5fc32486a6cb0af78fb6eaa9..76c7829cf8fdadad378305ba795212ac10f621ea 100644 --- a/en/application-dev/reference/apis/js-apis-socket.md +++ b/en/application-dev/reference/apis/js-apis-socket.md @@ -1,6 +1,6 @@ # # @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** > @@ -34,7 +34,7 @@ let udp = socket.constructUDPSocketInstance(); ## UDPSocket7+ -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. ### bind7+ @@ -118,7 +118,7 @@ promise.then(() => { send(options: UDPSendOptions, callback: AsyncCallback\): 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. @@ -130,7 +130,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p | 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\ | Yes | Callback used to return the result. | **Error codes** @@ -164,7 +164,7 @@ udp.send({ send(options: UDPSendOptions): Promise\ -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. @@ -176,7 +176,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p | 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** @@ -214,7 +214,7 @@ promise.then(() => { close(callback: AsyncCallback\): 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 @@ -243,7 +243,7 @@ udp.close(err => { close(): Promise\ -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 @@ -271,7 +271,7 @@ promise.then(() => { getState(callback: AsyncCallback\): 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** > 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 => { getState(): Promise\ -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** > This API can be called only after **bind** is successfully called. @@ -355,7 +355,7 @@ promise.then(err => { setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\): 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** > 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 | 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\ | Yes | Callback used to return the result. | **Error codes** @@ -408,7 +408,7 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { setExtraOptions(options: UDPExtraOptions): Promise\ -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** > 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 | 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** @@ -464,7 +464,7 @@ promise.then(() => { 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 @@ -495,10 +495,10 @@ udp.on('message', value => { 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** -> 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 @@ -524,7 +524,7 @@ let callback = value => { console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); } 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'); ``` @@ -533,7 +533,7 @@ udp.off('message'); on(type: 'listening' | 'close', callback: Callback\): 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 @@ -560,10 +560,10 @@ udp.on('close', () => { off(type: 'listening' | 'close', callback?: Callback\): 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** -> 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 @@ -582,14 +582,14 @@ let callback1 = () => { console.log("on listening, success"); } 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'); let callback2 = () => { console.log("on close, success"); } 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'); ``` @@ -598,7 +598,7 @@ udp.off('close'); 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 @@ -622,10 +622,10 @@ udp.on('error', err => { 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** -> 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 @@ -644,7 +644,7 @@ let callback = err => { console.log("on error, err:" + JSON.stringify(err)); } 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'); ``` @@ -663,7 +663,7 @@ Defines the destination address. ## UDPSendOptions7+ -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 @@ -674,7 +674,7 @@ Defines the parameters for sending data over the UDPSocket connection. ## UDPExtraOptions7+ -Defines other properties of the UDPSocket connection. +Defines other properties of the UDP socket connection. **System capability**: SystemCapability.Communication.NetStack @@ -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**. | | 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**. | -| 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**.| ## SocketStateBase7+ @@ -739,7 +739,7 @@ let tcp = socket.constructTCPSocketInstance(); ## TCPSocket7+ -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. ### bind7+ @@ -747,6 +747,9 @@ bind(address: NetAddress, callback: AsyncCallback\): 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. +> **NOTE** +> If the operation fails, the system randomly allocates a port number. + **Required permissions**: ohos.permission.INTERNET **System capability**: SystemCapability.Communication.NetStack @@ -784,6 +787,9 @@ bind(address: NetAddress): Promise\ 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 **System capability**: SystemCapability.Communication.NetStack @@ -836,7 +842,7 @@ Sets up a connection to the specified IP address and port number. This API uses | 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\ | Yes | Callback used to return the result. | **Error codes** @@ -873,7 +879,7 @@ Sets up a connection to the specified IP address and port number. This API uses | 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** @@ -904,7 +910,7 @@ promise.then(() => { send(options: TCPSendOptions, callback: AsyncCallback\): 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** > 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 | 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\ | Yes | Callback used to return the result. | **Error codes** @@ -950,7 +956,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim send(options: TCPSendOptions): Promise\ -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** > 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 | 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** @@ -1002,7 +1008,7 @@ promise1.then(() => { close(callback: AsyncCallback\): 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 @@ -1037,7 +1043,7 @@ tcp.close(err => { close(): Promise\ -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 @@ -1155,7 +1161,7 @@ promise1.then(() => { getState(callback: AsyncCallback\): 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** > 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 getState(): Promise\ -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** > This API can be called only after **bind** or **connect** is successfully called. @@ -1235,11 +1241,92 @@ promise.then(() => { }); ``` +### getSocketFd10+ + +getSocketFd(callback: AsyncCallback\): 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\ | 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 + }) +``` +### getSocketFd10+ + +getSocketFd(): Promise\ + +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\ | 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 + }) +``` + ### setExtraOptions7+ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\): 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** > 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 | 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\ | Yes | Callback used to return the result. | **Error codes** @@ -1291,7 +1378,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa setExtraOptions(options: TCPExtraOptions): Promise\ -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** > 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 | 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** @@ -1350,7 +1437,7 @@ promise.then(() => { 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 @@ -1381,10 +1468,10 @@ tcp.on('message', value => { 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** -> 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 @@ -1410,7 +1497,7 @@ let callback = value => { console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); } 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'); ``` @@ -1419,7 +1506,7 @@ tcp.off('message'); on(type: 'connect' | 'close', callback: Callback\): 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 @@ -1446,10 +1533,10 @@ tcp.on('close', () => { off(type: 'connect' | 'close', callback?: Callback\): 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** -> 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 @@ -1468,14 +1555,14 @@ let callback1 = () => { console.log("on connect success"); } 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'); let callback2 = () => { console.log("on close success"); } 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'); ``` @@ -1484,7 +1571,7 @@ tcp.off('close'); 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 @@ -1508,10 +1595,10 @@ tcp.on('error', err => { 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** -> 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 @@ -1530,25 +1617,25 @@ let callback = err => { console.log("on error, err:" + JSON.stringify(err)); } 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'); ``` ## TCPConnectOptions7+ -Defines TCPSocket connection parameters. +Defines TCP socket connection parameters. **System capability**: SystemCapability.Communication.NetStack | Name | Type | Mandatory| Description | | ------- | ---------------------------------- | ---- | -------------------------- | | 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.| ## TCPSendOptions7+ -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 @@ -1559,7 +1646,7 @@ Defines the parameters for sending data over the TCPSocket connection. ## TCPExtraOptions7+ -Defines other properties of the TCPSocket connection. +Defines other properties of the TCP socket connection. **System capability**: SystemCapability.Communication.NetStack @@ -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**. | | 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.
- **on**: whether to enable socket linger. The value true means to enable socket linger and false means the opposite.
- **linger**: linger time, in ms. The value ranges from **0** to **65535**.
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**. | | 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**. | -| 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.constructTCPSocketServerInstance10+ @@ -1602,10 +1689,10 @@ Defines a TCPSocketServer connection. Before calling TCPSocketServer APIs, you n listen(address: NetAddress, callback: AsyncCallback\): 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** -> 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 @@ -1647,10 +1734,10 @@ tcpServer.listen({ address: "192.168.xx.xxx", port: xxxx, family: 1 }, err => { listen(address: NetAddress): Promise\ -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** -> 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 @@ -1908,7 +1995,10 @@ promise.then(() => { on(type: 'connect', callback: Callback\): 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 @@ -1938,10 +2028,10 @@ tcpServer.on('connect', function(data) { off(type: 'connect', callback?: Callback\): 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** -> 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 @@ -1966,7 +2056,7 @@ let callback = data => { console.log('on connect message: ' + JSON.stringify(data)); } 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'); ``` @@ -1975,7 +2065,10 @@ tcpServer.off('connect'); 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 @@ -2005,10 +2098,10 @@ tcpServer.on('error', err => { 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** -> 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 @@ -2033,7 +2126,7 @@ let callback = err => { console.log("on error, err:" + JSON.stringify(err)); } 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'); ``` @@ -2147,7 +2240,7 @@ tcpServer.on('connect', function(client) { close(callback: AsyncCallback\): 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 @@ -2186,7 +2279,7 @@ tcpServer.on('connect', function(client) { close(): Promise\ -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 @@ -2307,7 +2400,7 @@ tcpServer.on('connect', function(client) { 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 @@ -2346,10 +2439,10 @@ tcpServer.on('connect', function(client) { 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** -> 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 @@ -2382,7 +2475,7 @@ let callback = value => { let tcpServer = socket.constructTCPSocketServerInstance(); tcpServer.on('connect', function(client) { 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'); }); @@ -2392,7 +2485,7 @@ tcpServer.on('connect', function(client) { on(type: 'close', callback: Callback\): 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 @@ -2424,10 +2517,10 @@ tcpServer.on('connect', function(client) { on(type: 'close', callback: Callback\): 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** -> 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 @@ -2453,7 +2546,7 @@ let callback = () => { let tcpServer = socket.constructTCPSocketServerInstance(); tcpServer.on('connect', function(client) { 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'); }); @@ -2463,7 +2556,7 @@ tcpServer.on('connect', function(client) { 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 @@ -2495,10 +2588,10 @@ tcpServer.on('connect', function(client) { 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** -> 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 @@ -2524,7 +2617,7 @@ let callback = err => { let tcpServer = socket.constructTCPSocketServerInstance(); tcpServer.on('connect', function(client) { 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'); }); @@ -2558,7 +2651,7 @@ let tls = socket.constructTLSSocketInstance(); ## TLSSocket9+ -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. ### bind9+ @@ -2644,7 +2737,7 @@ promise.then(() => { getState(callback: AsyncCallback\): 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 @@ -2652,7 +2745,7 @@ Obtains the status of the TLSSocket connection. This API uses an asynchronous ca | 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** @@ -2684,7 +2777,7 @@ tls.getState((err, data) => { getState(): Promise\ -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 @@ -2722,7 +2815,7 @@ promise.then(() => { setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\): 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 @@ -2730,8 +2823,8 @@ Sets other properties of the TCPSocket connection after **bind** is successfully | Name | Type | Mandatory| Description | | -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ | -| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).| -| callback | AsyncCallback\ | 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.| +| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).| +| callback | AsyncCallback\ | 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** @@ -2774,7 +2867,7 @@ tls.setExtraOptions({ setExtraOptions(options: TCPExtraOptions): Promise\ -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 @@ -2782,7 +2875,7 @@ Sets other properties of the TCPSocket connection after **bind** is successfully | 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** @@ -2829,7 +2922,7 @@ promise.then(() => { 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 @@ -2860,10 +2953,10 @@ tls.on('message', value => { 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** -> 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 @@ -2872,7 +2965,7 @@ Disables listening for **message** events of the TLSSocket connection. This API | Name | Type | Mandatory| Description | | -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- | | type | string | Yes | Type of the event to subscribe to.
**message**: message receiving event.| -| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result.
**message**: received message.
**remoteInfo**: socket connection information.| +| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result.
**message**: received message.
**remoteInfo**: socket connection information.| **Example** @@ -2889,14 +2982,14 @@ let callback = value => { console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo)); } 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); ``` ### on('connect' | 'close')9+ on(type: 'connect' | 'close', callback: Callback\): 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 @@ -2923,10 +3016,10 @@ tls.on('close', () => { off(type: 'connect' | 'close', callback?: Callback\): 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** -> 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 @@ -2945,14 +3038,14 @@ let callback1 = () => { console.log("on connect success"); } 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'); let callback2 = () => { console.log("on close success"); } 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); ``` @@ -2960,7 +3053,7 @@ tls.off('close', callback2); 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 @@ -2984,10 +3077,10 @@ tls.on('error', err => { 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** -> 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 @@ -3006,7 +3099,7 @@ let callback = err => { console.log("on error, err:" + JSON.stringify(err)); } 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); ``` @@ -3014,7 +3107,7 @@ tls.off('error', callback); connect(options: TLSConnectOptions, callback: AsyncCallback\): 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 @@ -3022,7 +3115,7 @@ Sets up a TLSSocket connection, and creates and initializes a TLS session after | 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\ | 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** @@ -3108,7 +3201,7 @@ tlsOneWay.connect(oneWayOptions, (err, data) => { connect(options: TLSConnectOptions): Promise\ -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 @@ -3209,7 +3302,7 @@ tlsOneWay.connect(oneWayOptions).then(data => { getRemoteAddress(callback: AsyncCallback\): 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 @@ -3242,7 +3335,7 @@ tls.getRemoteAddress((err, data) => { getRemoteAddress(): Promise\ -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 @@ -3274,7 +3367,7 @@ promise.then(() => { 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 @@ -3308,7 +3401,7 @@ tls.getCertificate((err, data) => { 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 @@ -3340,7 +3433,7 @@ tls.getCertificate().then(data => { 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 @@ -3373,7 +3466,7 @@ tls.getRemoteCertificate((err, data) => { 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 @@ -3404,7 +3497,7 @@ tls.getRemoteCertificate().then(data => { getProtocol(callback: AsyncCallback\): 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 @@ -3438,7 +3531,7 @@ tls.getProtocol((err, data) => { getProtocol():Promise\ -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 @@ -3470,7 +3563,7 @@ tls.getProtocol().then(data => { getCipherSuite(callback: AsyncCallback\\>): 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 @@ -3505,7 +3598,7 @@ tls.getCipherSuite((err, data) => { getCipherSuite(): Promise\\> -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 @@ -3538,7 +3631,7 @@ tls.getCipherSuite().then(data => { getSignatureAlgorithms(callback: AsyncCallback\\>): 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 @@ -3571,7 +3664,7 @@ tls.getSignatureAlgorithms((err, data) => { getSignatureAlgorithms(): Promise\\> -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 @@ -3602,7 +3695,7 @@ tls.getSignatureAlgorithms().then(data => { send(data: string, callback: AsyncCallback\): 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 @@ -3640,7 +3733,7 @@ tls.send("xxxx", (err) => { send(data: string): Promise\ -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 @@ -3681,7 +3774,7 @@ tls.send("xxxx").then(() => { close(callback: AsyncCallback\): 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 @@ -3717,7 +3810,7 @@ tls.close((err) => { close(): Promise\ -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 @@ -3815,7 +3908,7 @@ let tlsServer = socket.constructTLSSocketServerInstance(); ## TLSSocketServer10+ -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. ### listen10+ @@ -3950,7 +4043,7 @@ tlsServer.listen(options).then(() => { getState(callback: AsyncCallback\): 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** > 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. | 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** @@ -4011,7 +4104,7 @@ tlsServer.getState((err, data) => { getState(): Promise\ -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** > This API can be called only after **listen** is successfully called. @@ -4071,7 +4164,7 @@ promise.then(() => { setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\): 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** > 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 | 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\ | 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** @@ -4141,7 +4234,7 @@ tlsServer.setExtraOptions({ setExtraOptions(options: TCPExtraOptions): Promise\ -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** > 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 | 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** @@ -4217,7 +4310,7 @@ promise.then(() => { 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** > This API can be called only after **listen** is successfully called. @@ -4278,7 +4371,7 @@ tlsServer.getCertificate((err, data) => { 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** > This API can be called only after **listen** is successfully called. @@ -4338,7 +4431,7 @@ tlsServer.getCertificate().then(data => { getProtocol(callback: AsyncCallback\): 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** > This API can be called only after **listen** is successfully called. @@ -4399,7 +4492,7 @@ tlsServer.getProtocol((err, data) => { getProtocol():Promise\ -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** > This API can be called only after **listen** is successfully called. @@ -4453,11 +4546,11 @@ tlsServer.getProtocol().then(data => { }); ``` -### on('connect') +### on('connect')10+ on(type: 'connect', callback: Callback\): 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** > This API can be called only after **listen** is successfully called. @@ -4508,14 +4601,15 @@ tlsServer.on('connect', function(data) { }); ``` -### off('connect') +### off('connect')10+ off(type: 'connect', callback?: Callback\): 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** -> 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 @@ -4564,16 +4658,16 @@ tlsServer.listen(options).then(() => { return; }); 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'); ``` -### on('error') +### on('error')10+ 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** > This API can be called only after **listen** is successfully called. @@ -4624,14 +4718,15 @@ tlsServer.on('error', err => { }); ``` -### off('error') +### off('error')10+ 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** -> 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 @@ -4680,7 +4775,7 @@ tlsServer.listen(options).then(() => { return; }); 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'); ``` @@ -4704,7 +4799,7 @@ Defines a **TLSSocketConnection** object, that is, the connection between the TL send(data: string, callback: AsyncCallback\): 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 @@ -4712,7 +4807,7 @@ Sends a message to the client after a TLSSocketServer connection is established. | 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\ | 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** @@ -4767,7 +4862,7 @@ tlsServer.on('connect', function(client) { send(data: string): Promise\ -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 @@ -4775,7 +4870,7 @@ Sends a message to the server after a TLSSocketServer connection is established. | 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** @@ -4836,7 +4931,7 @@ tlsServer.on('connect', function(client) { close(callback: AsyncCallback\): 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 @@ -4897,7 +4992,7 @@ tlsServer.on('connect', function(client) { close(): Promise\ -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 @@ -4958,7 +5053,7 @@ tlsServer.on('connect', function(client) { getRemoteAddress(callback: AsyncCallback\): 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 @@ -5017,7 +5112,7 @@ tlsServer.on('connect', function(client) { getRemoteAddress(): Promise\ -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 @@ -5075,7 +5170,7 @@ tlsServer.on('connect', function(client) { 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 @@ -5134,7 +5229,7 @@ tlsServer.on('connect', function(client) { 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 @@ -5192,7 +5287,7 @@ tlsServer.on('connect', function(client) { getCipherSuite(callback: AsyncCallback\\>): 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 @@ -5253,7 +5348,7 @@ tlsServer.on('connect', function(client) { getCipherSuite(): Promise\\> -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 @@ -5313,7 +5408,7 @@ tlsServer.on('connect', function(client) { getSignatureAlgorithms(callback: AsyncCallback\\>): 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 @@ -5372,7 +5467,7 @@ tlsServer.on('connect', function(client) { getSignatureAlgorithms(): Promise\\> -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 @@ -5430,7 +5525,7 @@ tlsServer.on('connect', function(client) { 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 @@ -5491,10 +5586,10 @@ tlsServer.on('connect', function(client) { 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** -> 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 @@ -5551,7 +5646,7 @@ tlsServer.listen(options).then(() => { }); tlsServer.on('connect', function(client) { 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'); }); @@ -5561,7 +5656,7 @@ tlsServer.on('connect', function(client) { on(type: 'close', callback: Callback\): 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 @@ -5615,10 +5710,10 @@ tlsServer.on('connect', function(client) { on(type: 'close', callback: Callback\): 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** -> 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 @@ -5668,7 +5763,7 @@ tlsServer.listen(options).then(() => { }); tlsServer.on('connect', function(client) { 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'); }); @@ -5678,7 +5773,7 @@ tlsServer.on('connect', function(client) { 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 @@ -5732,10 +5827,10 @@ tlsServer.on('connect', function(client) { 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** -> 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 @@ -5785,7 +5880,7 @@ tlsServer.listen(options).then(() => { }); tlsServer.on('connect', function(client) { 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'); }); diff --git a/en/application-dev/reference/apis/js-apis-usb-deprecated.md b/en/application-dev/reference/apis/js-apis-usb-deprecated.md index f5c4bc2d05b1ac5e085f573c1730882afc38a03c..09435e9ce50ace4533694004f3dcb4896236feaf 100644 --- a/en/application-dev/reference/apis/js-apis-usb-deprecated.md +++ b/en/application-dev/reference/apis/js-apis-usb-deprecated.md @@ -137,7 +137,7 @@ Checks whether the application has the permission to access the device. **Example** ```js -let devicesName="1-1"; +let devicesName= "1-1"; let bool = usb.hasRight(devicesName); console.log(bool); ``` @@ -165,7 +165,7 @@ Requests the temporary permission for the application to access a USB device. Th **Example** ```js -let devicesName="1-1"; +let devicesName= "1-1"; usb.requestRight(devicesName).then((ret) => { console.log(`requestRight = ${ret}`); }); @@ -375,7 +375,14 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **Example** ```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) => { console.log(`controlTransfer = ${ret}`); }) @@ -500,7 +507,7 @@ Converts the USB function list in the numeric mask format to a string in Device **Example** ```js -let funcs = usb.ACM | usb.ECM; +let funcs = usb.FunctionType.ACM | usb.FunctionType.ECM; let ret = usb.usbFunctionsToString(funcs); ``` @@ -529,8 +536,12 @@ Sets the current USB function list in Device mode. **Example** ```js -let funcs = usb.HDC; -let ret = usb.setCurrentFunctions(funcs); +let funcs = usb.FunctionType.HDC; +usb.setCurrentFunctions(funcs).then(() => { + console.info('usb setCurrentFunctions successfully.'); +}).catch(err => { + console.error('usb setCurrentFunctions failed: ' + err.code + ' message: ' + err.message); +}); ``` ## usb.getCurrentFunctions9+ @@ -848,7 +859,7 @@ Enumerates power role types. | Name | Value | Description | | ------ | ---- | ---------- | -| NONE | 0 | None | +| NONE | 0 | None. | | SOURCE | 1 | External power supply.| | SINK | 2 | Internal power supply.| @@ -862,6 +873,6 @@ Enumerates data role types. | Name | Value | Description | | ------ | ---- | ------------ | -| NONE | 0 | None | +| NONE | 0 | None. | | HOST | 1 | USB host.| | DEVICE | 2 | USB device.| diff --git a/en/application-dev/reference/errorcodes/errorcode-resource-manager.md b/en/application-dev/reference/errorcodes/errorcode-resource-manager.md index 0087cce7e7069ed7efcab185e3c51be883dee13e..23d0479485e3628c0a1d22ac41ec3b1157c7d11a 100644 --- a/en/application-dev/reference/errorcodes/errorcode-resource-manager.md +++ b/en/application-dev/reference/errorcodes/errorcode-resource-manager.md @@ -177,3 +177,21 @@ System resources are not loaded to the sandbox path of the application process. **Solution** 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. diff --git a/en/device-dev/get-code/sourcecode-acquire.md b/en/device-dev/get-code/sourcecode-acquire.md index 66a5f7d425f4a0d7f97cbf5ba4a3772d7d9ebaef..bda7306a445adef5ce83ea0195fc0d0f5a18bd8e 100644 --- a/en/device-dev/get-code/sourcecode-acquire.md +++ b/en/device-dev/get-code/sourcecode-acquire.md @@ -157,8 +157,9 @@ You must install **Node.js** and HPM on your local PC. The installation procedur 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. - 2. Click **Download** if you want to download the distribution to your local PC. - 3. Click **Device component tailoring** if you want to add or delete components of the distribution. + 2. Use either of the following modes to obtain the source code: + - 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 diff --git a/en/device-dev/subsystems/figures/en-us_image_0000001151931738.jpg b/en/device-dev/subsystems/figures/en-us_image_0000001151931738.jpg index b0b149f4db5af1e17aca7ee6a422da45d31b7b4d..7003d3577b93fb795046223302054b06980e8193 100644 Binary files a/en/device-dev/subsystems/figures/en-us_image_0000001151931738.jpg and b/en/device-dev/subsystems/figures/en-us_image_0000001151931738.jpg differ diff --git a/en/device-dev/subsystems/subsys-ai-aiframework-devguide.md b/en/device-dev/subsystems/subsys-ai-aiframework-devguide.md index 793db13e3a40f8ce542d4bafa17173b6e464f08c..1fb1bb3f3482b6aa08e6b5499423562e7c04e42d 100644 --- a/en/device-dev/subsystems/subsys-ai-aiframework-devguide.md +++ b/en/device-dev/subsystems/subsys-ai-aiframework-devguide.md @@ -1,17 +1,14 @@ -# AI Framework Development +# AI Framework Development Guide ## **Overview** ### 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 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 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 following figure shows the AI engine framework. + **Figure 1** AI engine framework ![en-us_image_0000001200128073](figures/en-us_image_0000001200128073.png) @@ -22,11 +19,11 @@ The following figure shows the AI engine framework. 2. [Download the source code.](../get-code/sourcecode-acquire.md) -## Technical specifications +## Technical Specifications ### 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. @@ -37,9 +34,9 @@ The following figure shows the code dependency between modules of the AI engine ![en-us_image_0000001151931738](figures/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 @@ -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. -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. @@ -65,14 +62,14 @@ Plug-in loading on the server uses the dlopen mode and can only be performed in ### Naming rule -#### Rule: Name an SDK in the format of **domain\_keyword<*other information 1*\_*other information 2*\_…>\_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**. -#### Rule: Name a plug-in in the format of **domain\_keyword<*other information 1*\_*other information 2*\_…>.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**. @@ -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. ``` -> **NOTE** -> -> - 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. -> - 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. +Note: + +- 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. + +- 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. @@ -249,7 +251,7 @@ The following table describes the data structure of **ConfigInfo**, **ClientInfo | ConfigInfo | Algorithm configuration item information| **const char \*description**: body of configuration item information. | | ClientInfo | Client information.| **long long clientVersion**: client version number. This parameter is not used currently.
**int clientId**: client ID.
**int sessionId**: session ID.
**uid\_t serverUid**: server UID.
**uid\_t clientUid**: client UID.
**int extendLen**: length of the extended information (**extendMsg**).
**unsigned char \*extendMsg**: body of the extended information. | | AlgorithmInfo | Algorithm information| **long long clientVersion**: client version number. This parameter is not used currently.
**bool isAsync**: whether asynchronous execution is used.
**int algorithmType**: algorithm type ID allocated by the AI engine framework based on the plug-in loading sequence.
**long long algorithmVersion**: algorithm version number.
**bool isCloud**: whether to migrate data to the cloud. This parameter is not used currently.
**int operateId**: execution ID. This parameter is not used currently.
**int requestId**: request ID, which identifies each request and corresponds to the execution result.
**int extendLen**: length of the extended information (**extendMsg**).
**unsigned char \*extendMsg**: body of the extended information. | -| DataInfo | Algorithm input parameter configuration information (**inputInfo**) and output parameter configuration information (**outputInfo**)| **unsigned char \*data**: data subject.
**int length**: data length. | +| DataInfo | Algorithm input parameter configuration information (**inputInfo**)
and output parameter configuration information (**outputInfo**)| **unsigned char \*data**: data subject.
**int length**: data length. | 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. | Attribute| Description| Default Value| | -------- | -------- | -------- | -| innerSequenceId_ | Type: long long
**Function**: reserved| 0 | +| innerSequenceId_ | **Type**: long long
**Function**: reserved| 0 | | requestId_ | **Type**: int
**Function**: Indicates the request sequence, which is used to bind the return result.| 0 | | retCode__ | **Type**: int
**Function**: Indicates the inference result code of the asynchronous algorithm.| 0 | | retDesc_ | **Type**: string
**Function**: reserved| - | @@ -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.| | 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** -> -> - 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. + Note: + + 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. + + 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. ``` diff --git a/en/device-dev/subsystems/subsys-ai-nnrt-guide.md b/en/device-dev/subsystems/subsys-ai-nnrt-guide.md index c0d4a951d49e583bbeecbafcc844f9089e8e2a9b..992db3d549786a990b7200458f4ce34b940f5632 100644 --- a/en/device-dev/subsystems/subsys-ai-nnrt-guide.md +++ b/en/device-dev/subsystems/subsys-ai-nnrt-guide.md @@ -4,9 +4,9 @@ ### 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 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 ![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 ### 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. -> **NOTE**
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. +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**
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 -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 - -To connect the acceleration chip to NNRt, perform the development procedure below. - +The following uses the RK3568 chip as an example to describe the development procedure. #### 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. 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 - ./build.sh --product-name productname –ccache --build-target drivers_interface_nnrt + ./build.sh --product-name rk3568 –ccache --build-target drivers_interface_nnrt ``` - > **NOTE**
**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 language = "c" @@ -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: ```text out/rk3568/gen/drivers/interface/nnrt - └── v1_0 - ├── drivers_interface_nnrt__libnnrt_proxy_1.0_external_deps_temp.json - ├── drivers_interface_nnrt__libnnrt_stub_1.0_external_deps_temp.json + └── v2_0 + ├── drivers_interface_nnrt__libnnrt_proxy_2.0_external_deps_temp.json + ├── drivers_interface_nnrt__libnnrt_stub_2.0_external_deps_temp.json ├── innrt_device.h # Header file of the HDI ├── iprepared_model.h # Header file of the AI model - ├── libnnrt_proxy_1.0__notice.d - ├── libnnrt_stub_1.0__notice.d + ├── libnnrt_proxy_2.0__notice.d + ├── libnnrt_stub_2.0__notice.d ├── model_types.cpp # Implementation file for AI model structure definition ├── model_types.h # Header file for AI model structure definition ├── nnrt_device_driver.cpp # Device driver implementation example @@ -85,7 +81,7 @@ Download the OpenHarmony source code from the open source community, build the ` ├── nnrt_device_stub.cpp ├── nnrt_device_stub.h ├── 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.h # Header file for AI model operator attribute definition ├── prepared_model_proxy.cpp @@ -98,55 +94,58 @@ Download the OpenHarmony source code from the open source community, build the ` #### 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 drivers/peripheral/nnrt - ├── BUILD.gn # Code build script ├── bundle.json - └── hdi_cpu_service # Customized directory - ├── BUILD.gn # Code build script - ├── include - │ ├── nnrt_device_service.h # Header file for device services - │ ├── node_functions.h # Optional, depending on the actual implementation - │ ├── node_registry.h # Optional, depending on the actual implementation - │ └── prepared_model_service.h # Header file for AI model services - └── src - ├── nnrt_device_driver.cpp # Implementation file for the device driver - ├── nnrt_device_service.cpp # Implementation file for device services - ├── nnrt_device_stub.cpp # Optional, depending on the actual implementation - ├── node_attr_types.cpp # Optional, depending on the actual implementation - ├── 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 + ├── v2_0 + ├── BUILD.gn # Code build script + └── hdi_cpu_service # Customized directory + ├── BUILD.gn # Code build script + ├── include + │ ├── nnrt_device_service.h # Header file for device services + │ ├── node_functions.h # Optional, depending on the actual implementation + │ ├── node_registry.h # Optional, depending on the actual implementation + │ └── prepared_model_service.h # Header file for AI model services + └── src + ├── nnrt_device_driver.cpp # Implementation file for the device driver + ├── nnrt_device_service.cpp # Implementation file for device services + ├── nnrt_device_stub.cpp # Optional, depending on the actual implementation + ├── node_attr_types.cpp # Optional, depending on the actual implementation + ├── 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 import("//build/ohos.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 = [] sources = [ "src/nnrt_device_service.cpp", - "src/prepared_model_service.cpp", - "src/node_registry.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 = [ - "hdf_core:libhdf_utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_single", "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 ] @@ -157,15 +156,17 @@ Download the OpenHarmony source code from the open source community, build the ` ohos_shared_library("libnnrt_driver") { include_dirs = [] sources = [ "src/nnr_device_driver.cpp" ] - deps = [ "//drivers/peripheral/nnrt/hdi_cpu_service:libnnrt_service_1.0" ] + deps = [ ":libnnrt_service_2.0" ] external_deps = [ + "c_utils:utils", + "drivers_interface_nnrt:libnnrt_stub_2.0", "hdf_core:libhdf_host", "hdf_core:libhdf_ipc_adapter", "hdf_core:libhdf_utils", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_single", - "c_utils:utils", + "hdf_core:libhdi", + "hilog_native:libhilog", + "ipc:ipc_core", ] install_images = [ chipset_base_dir ] @@ -176,22 +177,20 @@ Download the OpenHarmony source code from the open source community, build the ` group("hdf_nnrt_service") { deps = [ ":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 if (defined(ohos_lite)) { group("nnrt_entry") { - deps = [ ] + deps = [] } } else { group("nnrt_entry") { - deps = [ - "./hdi_cpu_service:hdf_nnrt_service", - ] + deps = [ "./hdi_cpu_service:hdf_nnrt_service" ] } } ``` @@ -201,7 +200,7 @@ Download the OpenHarmony source code from the open source community, build the ` { "name": "drivers_peripheral_nnrt", "description": "Neural network runtime device driver", - "version": "3.2", + "version": "4.0", "license": "Apache License 2.0", "component": { "name": "drivers_peripheral_nnrt", @@ -212,10 +211,10 @@ Download the OpenHarmony source code from the open source community, build the ` "ram": "2048KB", "deps": { "components": [ - "ipc", + "c_utils", "hdf_core", - "hiviewdfx_hilog_native", - "c_utils" + "hilog_native", + "ipc" ], "third_part": [ "bounds_checking_function" @@ -223,7 +222,7 @@ Download the OpenHarmony source code from the open source community, build the ` }, "build": { "sub_component": [ - "//drivers/peripheral/nnrt:nnrt_entry" + "//drivers/peripheral/nnrt/v2_0:nnrt_entry" ], "test": [ ], @@ -236,7 +235,7 @@ Download the OpenHarmony source code from the open source community, build the ` #### 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 nnrt :: host { hostName = "nnrt_host"; @@ -254,7 +253,7 @@ Download the OpenHarmony source code from the open source community, build the ` } } ``` -> **NOTE**
After modifying the `.hcs` file, you need to delete the `out` directory and build the file again for the modification to take effect. +> **NOTE**
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 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 ` #### 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**
`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 # Add the security context configuration. type nnrt_host, hdfdomain, domain; ``` - > **NOTE**
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, -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 +5. Add the following configuration to the `base/security/selinux/sepolicy/ohos_policy/drivers/adapter/vendor/hdf_devmgr.te` file: + ```text + # Add the security context configuration. + allow hdf_devmgr nnrt_host:binder { call transfer }; + 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 # Create the nnrt folder. 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 # Create the vendor folder. 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 ``` -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 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 samgr:binder { call }; 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 }; ``` +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 Access the `chipset_common.json` file. ```shell 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 { - "component": "drivers_peripheral_foo", + "component": "drivers_peripheral_nnrt", "features": [] } ``` @@ -329,27 +388,27 @@ rm -rf ./out ### 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 # Go to the hats directory. cd test/xts/hats - # Build the hats test cases. - ./build.sh suite=hats system_size=standard --product-name rk3568 + # Compile the `hats` test cases. + ./build.sh suite=hats system_size=standard product_name=rk3568 # Return to the root directory. 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 - # 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/ - # 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" ``` @@ -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" ``` - 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 ... [----------] Global test environment tear-down @@ -371,37 +430,40 @@ On completion of service development, you can use XTS to verify its basic functi ### Development Example 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 - 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. - - 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). - 1. Create the `mindspore` directory in `drivers/peripheral/nnrt`. + - 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). + - 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 - 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`. - 3. Create and copy the `schema` file of MindSpore Lite. + - Create and copy the `schema` file of MindSpore Lite. ```shell - # Create the mindspore_schema directory. - mkdir drivers/peripheral/nnrt/hdi_cpu_service/include/mindspore_schema + # Create the mindspore_schema folder. + mkdir drivers/peripheral/nnrt/v2_0/hdi_cpu_service/include/mindspore_schema - # Copy the schema file of MindSpore Lite. - cp third_party/mindspore/mindspore/lite/schema/* drivers/peripheral/nnrt/hdi_cpu_service/include/mindspore_schema/ + # Copy the MindSpore schema file from the third_party directory. + 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 - # 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 - # Create the mindspore subdirectory. - mkdir drivers/peripheral/nnrt/mindspore/mindspore + # Create the `mindspore` folder in the `drivers/peripheral/nnrt/v2_0/mindspore` directory. + mkdir drivers/peripheral/nnrt/v2_0/mindspore/mindspore - # Copy the dynamic library to drivers/peripheral/nnrt/mindspore/mindspore. - cp out/rk3568/package/phone/system/lib/libmindspore-lite.huawei.so 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/v2_0/mindspore/mindspore/ ``` 4. Follow the [development procedure](#development-procedure) to complete other configurations. diff --git a/en/device-dev/subsystems/subsys-dfx-hitracemeter.md b/en/device-dev/subsystems/subsys-dfx-hitracemeter.md index 747c4ffc0f431028ffbd5f0c9e1a6d8e0b027563..28efbbb036af6040d0ebdd83a0a6de4df2bba634 100644 --- a/en/device-dev/subsystems/subsys-dfx-hitracemeter.md +++ b/en/device-dev/subsystems/subsys-dfx-hitracemeter.md @@ -223,7 +223,7 @@ The following is a demo debugging process, where the **StartTrace** and **Finish external_deps = [ "hitrace:hitrace_meter" ] subsystem_name = "hiviewdfx" - part_name = "hitrace" + part_name = "hitrace_native" } group("hitrace_target") { diff --git a/en/device-dev/subsystems/subsys-thermal_charging_idle_state.md b/en/device-dev/subsystems/subsys-thermal_charging_idle_state.md index a90cce407a05f26b2a1349561a5cdcf2f87411d0..4c01a0687cb97c5b7f626b16a6f7834ad2eeedee 100644 --- a/en/device-dev/subsystems/subsys-thermal_charging_idle_state.md +++ b/en/device-dev/subsystems/subsys-thermal_charging_idle_state.md @@ -88,7 +88,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma "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). diff --git a/en/device-dev/subsystems/subsys-thermal_control.md b/en/device-dev/subsystems/subsys-thermal_control.md index 5dbb6ab4e90a28834d4b7140be7c19a05a262ec7..e5262cb7e3950e32db6542d3a1da15de87ee06bb 100644 --- a/en/device-dev/subsystems/subsys-thermal_control.md +++ b/en/device-dev/subsystems/subsys-thermal_control.md @@ -106,7 +106,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma "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). @@ -150,7 +150,6 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ``` ## 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). Packing path: `/vendor/etc/thermal_config/hdf` diff --git a/en/device-dev/subsystems/subsys-thermal_level.md b/en/device-dev/subsystems/subsys-thermal_level.md index b7afd9404d6e24417fd6d0f957d0c8ab18ce64fc..bc8049ff2748446c61c2004dc56652b27b55855d 100644 --- a/en/device-dev/subsystems/subsys-thermal_level.md +++ b/en/device-dev/subsystems/subsys-thermal_level.md @@ -111,7 +111,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma "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). diff --git a/en/device-dev/subsystems/subsys-thermal_log.md b/en/device-dev/subsystems/subsys-thermal_log.md index a9b9b5f7ae4dbc0796c4064fe2102c060e41b9cc..2e889e833a99a13a492ce58c2c2cc04ab0643423 100644 --- a/en/device-dev/subsystems/subsys-thermal_log.md +++ b/en/device-dev/subsystems/subsys-thermal_log.md @@ -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. -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: @@ -50,6 +50,8 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma | 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| **Table 2** Description of the node configuration @@ -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.| ```shell - + <value path="sys/class/thermal/thermal_zone0/temp"/> @@ -84,10 +86,10 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma thermal.para.dac: ```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 import("//build/ohos.gni") @@ -95,7 +97,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ohos_prebuilt_etc("thermal_hdf_config") { source = "thermal_hdi_config.xml" 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. } ``` @@ -149,7 +151,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma "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). diff --git a/en/device-dev/subsystems/subsys-thermal_policy.md b/en/device-dev/subsystems/subsys-thermal_policy.md index a93ccd57335a9fab1af4abfc7843063973fcf3ca..06d3d147db9df0df60444cf833f4254135dddb47 100644 --- a/en/device-dev/subsystems/subsys-thermal_policy.md +++ b/en/device-dev/subsystems/subsys-thermal_policy.md @@ -150,7 +150,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma "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). diff --git a/en/device-dev/subsystems/subsys-thermal_scene.md b/en/device-dev/subsystems/subsys-thermal_scene.md index 4db0af2defc5600c56e1af750553a3e50a770530..b4ecc3141d18f28fe831b8eda1fb75b3d769aca6 100644 --- a/en/device-dev/subsystems/subsys-thermal_scene.md +++ b/en/device-dev/subsystems/subsys-thermal_scene.md @@ -86,7 +86,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma "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).