diff --git a/en/application-dev/connectivity/http-request.md b/en/application-dev/connectivity/http-request.md
index da1a7e1c517f284037a41a88e2167b6d1d2406aa..a266e285245c932534873440fc777fd86ccd480d 100644
--- a/en/application-dev/connectivity/http-request.md
+++ b/en/application-dev/connectivity/http-request.md
@@ -1,6 +1,6 @@
# HTTP Data Request
-## Use Cases
+## When to Use
An application can initiate a data request over HTTP. Common HTTP methods include **GET**, **POST**, **OPTIONS**, **HEAD**, **PUT**, **DELETE**, **TRACE**, and **CONNECT**.
@@ -14,40 +14,49 @@ For details about how to apply for permissions, see [Access Control Development]
The following table provides only a simple description of the related APIs. For details, see [API Reference](../reference/apis/js-apis-http.md).
-| API | Description |
-| ----------------------------------------- | --------------------------------------------------------- |
-| createHttp() | Creates an HTTP request. |
-| request() | Initiates an HTTP request to a given URL. |
-| destroy() | Destroys an HTTP request. |
+| API | Description |
+| ----------------------------------------- | ----------------------------------- |
+| createHttp() | Creates an HTTP request. |
+| request() | Initiates an HTTP request to a given URL. |
+| request2()10+ | Initiates an HTTP network request based on the URL and returns a streaming response.|
+| destroy() | Destroys an HTTP request. |
| on(type: 'headersReceive') | Registers an observer for HTTP Response Header events. |
-| off(type: 'headersReceive') | Unregisters the observer for HTTP Response Header events. |
+| off(type: 'headersReceive') | Unregisters the observer for HTTP Response Header events.|
+| once\('headersReceive'\)8+ | Registers a one-time observer for HTTP Response Header events.|
+| on\('dataReceive'\)10+ | Registers an observer for events indicating receiving of HTTP streaming responses. |
+| off\('dataReceive'\)10+ | Unregisters the observer for events indicating receiving of HTTP streaming responses. |
+| on\('dataEnd'\)10+ | Registers an observer for events indicating completion of receiving HTTP streaming responses. |
+| off\('dataEnd'\)10+ | Unregisters the observer for events indicating completion of receiving HTTP streaming responses.|
+| on\('dataProgress'\)10+ | Registers an observer for events indicating progress of receiving HTTP streaming responses. |
+| off\('dataProgress'\)10+ | Unregisters the observer for events indicating progress of receiving HTTP streaming responses.|
## How to Develop
-1. Import the required HTTP module.
-2. Create an **HttpRequest** object.
-3. (Optional) Listen for HTTP Response Header events.
-4. Initiate an HTTP request to a given URL.
-5. (Optional) Process the HTTP Response Header event and the return result of the HTTP request.
+1. Import the **http** namespace from **@ohos.net.http.d.ts**.
+2. Call **createHttp()** to create an **HttpRequest** object.
+3. Call **httpRequest.on()** to subscribe to HTTP response header events. This API returns a response earlier than the request. You can subscribe to HTTP response header events based on service requirements.
+4. Call **httpRequest.request()** to initiate a network request. You need to pass in the URL and optional parameters of the HTTP request.
+5. Parse the returned result based on service requirements.
+6. Call **off()** to unsubscribe from HTTP response header events.
+7. Call **httpRequest.destroy()** to release resources after the request is processed.
```js
+// Import the http namespace.
import http from '@ohos.net.http';
-// Each HttpRequest corresponds to an HttpRequestTask object and cannot be reused.
+// Each httpRequest corresponds to an HTTP request task and cannot be reused.
let httpRequest = http.createHttp();
-
-// Subscribe to the HTTP response header, which is returned earlier than HttpRequest. You can subscribe to HTTP Response Header events based on service requirements.
-// on('headerReceive', AsyncCallback) will be replaced by on('headersReceive', Callback) in API version 8. 8+
+// This API is used to listen for the HTTP Response Header event, which is returned earlier than the result of the HTTP request. It is up to you whether to listen for HTTP Response Header events.
+// on('headerReceive', AsyncCallback) is replaced by on('headersReceive', Callback) since API version 8.
httpRequest.on('headersReceive', (header) => {
console.info('header: ' + JSON.stringify(header));
});
-
httpRequest.request(
- // Set the URL of the HTTP request. You need to define the URL. Set the parameters of the request in extraData.
+ // Customize EXAMPLE_URL in extraData on your own. It is up to you whether to add parameters to the URL.
"EXAMPLE_URL",
{
method: http.RequestMethod.POST, // Optional. The default value is http.RequestMethod.GET.
- // You can add the header field based on service requirements.
+ // You can add header fields based on service requirements.
header: {
'Content-Type': 'application/json'
},
@@ -55,21 +64,33 @@ httpRequest.request(
extraData: {
"data": "data to send",
},
- connectTimeout: 60000, // Optional. The default value is 60000, in ms.
+ expectDataType: http.HttpDataType.STRING, // Optional. This field specifies the type of the return data.
+ usingCache: true, // Optional. The default value is true.
+ priority: 1, // Optional. The default value is 1.
+ connectTimeout: 60000 // Optional. The default value is 60000, in ms.
readTimeout: 60000, // Optional. The default value is 60000, in ms.
+ usingProtocol: http.HttpProtocol.HTTP1_1, // Optional. The default protocol type is automatically specified by the system.
+ usingProxy: false, // Optional. By default, network proxy is not used. This field is supported since API 10.
}, (err, data) => {
if (!err) {
- // data.result contains the HTTP response. Parse the response based on service requirements.
- console.info('Result:' + data.result);
- console.info('code:' + data.responseCode);
- // data.header contains the HTTP response header. Parse the content based on service requirements.
+ // data.result carries the HTTP response. Parse the response based on service requirements.
+ console.info('Result:' + JSON.stringify(data.result));
+ console.info('code:' + JSON.stringify(data.responseCode));
+ // data.header carries the HTTP response header. Parse the content based on service requirements.
console.info('header:' + JSON.stringify(data.header));
- console.info('cookies:' + data.cookies); // 8+
+ console.info('cookies:' + JSON.stringify(data.cookies)); // 8+
} else {
console.info('error:' + JSON.stringify(err));
- // Call the destroy() method to destroy the request if it is no longer needed.
+ // Unsubscribe from HTTP Response Header events.
+ httpRequest.off('headersReceive');
+ // Call the destroy() method to release resources after HttpRequest is complete.
httpRequest.destroy();
}
}
);
```
+
+## Samples
+The following sample is provided to help you better understand how to develop the HTTP data request feature:
+- [`HTTP`: Data Request (ArkTS) (API9)](https://gitee.com/openharmony/applications_app_samples/tree/master/code/BasicFeature/Connectivity/Http)
+- [HTTP Communication (ArkTS) (API9)](https://gitee.com/openharmony/codelabs/tree/master/NetworkManagement/SmartChatEtsOH)
diff --git a/en/application-dev/connectivity/socket-connection.md b/en/application-dev/connectivity/socket-connection.md
index da5bea318e2b60da5641b9cf01ee73c926802c16..68e3433597881d891c87abd60b6f81abfc876028 100644
--- a/en/application-dev/connectivity/socket-connection.md
+++ b/en/application-dev/connectivity/socket-connection.md
@@ -1,46 +1,83 @@
# Socket Connection
+## Introduction
-## Use Cases
+The Socket Connection module allows an application to transmit data over a Socket connection through the TCP, UDP, or TLS protocol.
-Your application can transmit data through Socket connections. Currently, the TCP and UDP protocols are supported.
+## Basic Concepts
+- Socket: An abstraction of endpoints for bidirectional communication between application processes running on different hosts in a network.
+- TCP: Transmission Control Protocol, which is a byte stream–based transport layer communication protocol that is connection-oriented and reliable.
+- UDP: User Datagram Protocol, which is a simple datagram-oriented transport layer communication protocol.
+- TLS: Transport Layer Security, which is a protocol that ensures the data confidentiality and integrity between communication programs.
+
+## When to Use
+
+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
## Available APIs
-The Socket connection function is mainly implemented by the Socket module. The following table describes the related APIs.
+For the complete list of APIs and example code, see [Socket Connection](../reference/apis/js-apis-socket.md).
+
+Socket connection functions are mainly implemented by the **socket** module. The following table describes the related APIs.
-| API| Description |
+| API| Description|
| -------- | -------- |
-| constructUDPSocketInstance() | Creates a **UDPSocket** object. |
-| constructTCPSocketInstance() | Creates a **TCPSocket** object. |
-| bind() | Binds the IP address and port number. |
+| constructUDPSocketInstance() | Creates a **UDPSocket** object.|
+| constructTCPSocketInstance() | Creates a **TCPSocket** object.|
+| bind() | Binds the IP address and port number.|
| send() | Sends data.|
-| 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') | Enables listening for **message** events of the Socket connection. |
-| off(type: 'message') | Disables listening for **message** events of the Socket connection. |
-| on(type: 'close') | Enables listening for **close** events of the Socket connection. |
-| off(type: 'close') | Disables listening for **close** events of the Socket connection. |
-| on(type: 'error') | Enables listening for **error** events of the Socket connection. |
-| off(type: 'error') | Disables listening for **error** events of the Socket connection. |
-| on(type: 'listening') | Enables listening for **listening** events of the UDPSocket connection. |
-| off(type: 'listening') | Disables listening for **listening** events of the UDPSocket connection. |
-| on(type: 'connect') | Enables listening for **connect** events of the TCPSocket connection. |
-| off(type: 'connect') | Disables listening for **connect** events of the TCPSocket connection. |
+| 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.
+
+| API| Description|
+| -------- | -------- |
+| constructTLSSocketInstance() | Creates a **TLSSocket** object.|
+| bind() | Binds the IP address and port number.|
+| 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.|
+| 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.|
+| send() | Sends data.|
+| setExtraOptions() | Sets other properties of the TLS Socket connection.|
-## How to Develop
+## Transmitting Data over TCP/UDP Socket Connections
-The implementation is similar for UDPSocket and TCPSocket. The following uses the TCPSocket as an example.
+The implementation is similar for UDP Socket and TCP Socket connections. The following uses data transmission over a TCP Socket connection as an example.
-1. Import the required Socket module.
+1. Import the required **socket** module.
2. Create a **TCPSocket** object.
-3. (Optional) Enable listening for TCPSocket 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.
@@ -48,15 +85,15 @@ The implementation is similar for UDPSocket and TCPSocket. The following uses th
6. Send data.
-7. Enable the TCPSocket 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.
let tcp = socket.constructTCPSocketInstance();
-
- // Enable listening for TCPSocket events.
+
+ // Subscribe to TCP Socket connection events.
tcp.on('message', value => {
console.log("on message")
let buffer = value.message
@@ -73,7 +110,7 @@ The implementation is similar for UDPSocket and TCPSocket. The following uses th
tcp.on('close', () => {
console.log("on close")
});
-
+
// Bind the local IP address and port number.
let bindAddress = {
address: '192.168.xx.xx',
@@ -86,6 +123,7 @@ The implementation is similar for UDPSocket and TCPSocket. The following uses th
return;
}
console.log('bind success');
+
// Set up a connection to the specified IP address and port number.
let connectAddress = {
address: '192.168.xx.xx',
@@ -100,6 +138,7 @@ The implementation is similar for UDPSocket and TCPSocket. The following uses th
return;
}
console.log('connect success');
+
// Send data.
tcp.send({
data: 'Hello, server!'
@@ -112,7 +151,8 @@ The implementation is similar for UDPSocket and TCPSocket. The following uses th
})
});
});
- // Enable the TCPSocket connection to be automatically closed after use. Then, disable listening for TCPSocket events.
+
+ // Enable the TCP Socket connection to be automatically closed after use. Then, disable listening for TCP Socket connection events.
setTimeout(() => {
tcp.close((err) => {
console.log('close socket.')
@@ -122,3 +162,167 @@ The implementation is similar for UDPSocket and TCPSocket. The following uses th
tcp.off('close');
}, 30 * 1000);
```
+
+## Implementing Encrypted Data Transmission over TLS Socket Connections
+
+### How to Develop
+
+TLS Socket connection process on the client:
+
+1. Import the required **socket** module.
+
+2. Bind the IP address and port number of the server.
+
+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.
+
+5. (Optional) Subscribe to TLS Socket connection events.
+
+6. Send data.
+
+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).
+ let tlsTwoWay = socket.constructTLSSocketInstance();
+
+ // Subscribe to TLS Socket connection events.
+ tcp.on('message', value => {
+ console.log("on message")
+ 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("on connect received:" + str)
+ });
+ tcp.on('connect', () => {
+ console.log("on connect")
+ });
+ tcp.on('close', () => {
+ console.log("on close")
+ });
+
+ // Bind the local IP address and port number.
+ tlsTwoWay.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => {
+ if (err) {
+ console.log('bind fail');
+ return;
+ }
+ console.log('bind success');
+ });
+
+ // Set the communication parameters.
+ let options = {
+ ALPNProtocols: ["spdy/1", "http/1.1"],
+
+ // Set up a connection to the specified IP address and port number.
+ address: {
+ address: "192.168.xx.xxx",
+ port: xxxx, // Port
+ family: 1,
+ },
+
+ // Set the parameters used for authentication during communication.
+ secureOptions: {
+ key: "xxxx", // Key
+ cert: "xxxx", // Digital certificate
+ ca: ["xxxx"], // CA certificate
+ passwd: "xxxx", // Password for generating the key
+ protocols: [socket.Protocol.TLSv12], // Communication protocol
+ useRemoteCipherPrefer: true, // Whether to preferentially use the peer cipher suite
+ signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", // Signature algorithm
+ cipherSuite: "AES256-SHA256", // Cipher suite
+ },
+ };
+
+ // Set up a connection.
+ tlsTwoWay.connect(options, (err, data) => {
+ console.error(err);
+ console.log(data);
+ });
+
+ // Enable the TLS Socket connection to be automatically closed after use. Then, disable listening for TLS Socket connection events.
+ tls.close((err) => {
+ if (err) {
+ console.log("close callback error = " + err);
+ } else {
+ console.log("close success");
+ }
+ tls.off('message');
+ tls.off('connect');
+ tls.off('close');
+ });
+
+ // Create a TLS Socket connection (for one-way authentication).
+ let tlsOneWay = socket.constructTLSSocketInstance(); // One way authentication
+
+ // Subscribe to TLS Socket connection events.
+ tcp.on('message', value => {
+ console.log("on message")
+ 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("on connect received:" + str)
+ });
+ tcp.on('connect', () => {
+ console.log("on connect")
+ });
+ tcp.on('close', () => {
+ console.log("on close")
+ });
+
+ // Bind the local IP address and port number.
+ tlsOneWay.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => {
+ if (err) {
+ console.log('bind fail');
+ return;
+ }
+ console.log('bind success');
+ });
+
+ // Set the communication parameters.
+ let oneWayOptions = {
+ address: {
+ address: "192.168.xxx.xxx",
+ port: xxxx,
+ family: 1,
+ },
+ secureOptions: {
+ ca: ["xxxx","xxxx"], // CA certificate
+ cipherSuite: "AES256-SHA256", // Cipher suite
+ },
+ };
+
+ // Set up a connection.
+ tlsOneWay.connect(oneWayOptions, (err, data) => {
+ console.error(err);
+ console.log(data);
+ });
+
+ // Enable the TLS Socket connection to be automatically closed after use. Then, disable listening for TLS Socket connection events.
+ tls.close((err) => {
+ if (err) {
+ console.log("close callback error = " + err);
+ } else {
+ console.log("close success");
+ }
+ tls.off('message');
+ tls.off('connect');
+ tls.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/Network/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/device/pointerstyle-guidelines.md b/en/application-dev/device/pointerstyle-guidelines.md
index 06a904a5c5ed3a52dba9bf93bc0fa5a9e8a48690..bcc09093eed4440a0c5e62c5d4cfe37a3f954c87 100644
--- a/en/application-dev/device/pointerstyle-guidelines.md
+++ b/en/application-dev/device/pointerstyle-guidelines.md
@@ -77,43 +77,48 @@ When designing a color picker, you can have the mouse pointer switched to the co
5. Set the mouse pointer to the default style.
```js
+import pointer from '@ohos.multimodalInput.pointer';
import window from '@ohos.window';
// 1. Enable the color pickup function.
// 2. Obtain the window ID.
-window.getTopWindow((error, windowClass) => {
- windowClass.getProperties((error, data) => {
- var windowId = data.id;
- if (windowId < 0) {
- console.log(`Invalid windowId`);
- return;
- }
- try {
- // 3. Set the mouse pointer to the color picker style.
- pointer.setPointerStyle(windowId, pointer.PointerStyle.COLOR_SUCKER).then(() => {
- console.log(`Successfully set mouse pointer style`);
- });
- } catch (error) {
- console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(message)}`);
- }
- });
+window.getLastWindow(this.context, (error, windowClass) => {
+ if (error.code) {
+ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
+ return;
+ }
+ var windowId = windowClass.getWindowProperties().id;
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ // 3. Set the mouse pointer to the color picker style.
+ pointer.setPointerStyle(windowId, pointer.PointerStyle.COLOR_SUCKER).then(() => {
+ console.log(`Successfully set mouse pointer style`);
+ });
+ } catch (error) {
+ console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(`message`)}`);
+ }
});
// 4. End color pickup.
-window.getTopWindow((error, windowClass) => {
- windowClass.getProperties((error, data) => {
- var windowId = data.id;
- if (windowId < 0) {
- console.log(`Invalid windowId`);
- return;
- }
- try {
- // 5. Set the mouse pointer to the default style.
- pointer.setPointerStyle(windowId, pointer.PointerStyle.DEFAULT).then(() => {
- console.log(`Successfully set mouse pointer style`);
- });
- } catch (error) {
- console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(message)}`);
- }
- });
+window.getLastWindow(this.context, (error, windowClass) => {
+ if (error.code) {
+ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
+ return;
+ }
+ var windowId = windowClass.getWindowProperties().id;
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ // 5. Set the mouse pointer to the default style.
+ pointer.setPointerStyle(windowId, pointer.PointerStyle.DEFAULT).then(() => {
+ console.log(`Successfully set mouse pointer style`);
+ });
+ } catch (error) {
+ console.log(`Failed to set the pointer style, error=${JSON.stringify(error)}, msg=${JSON.stringify(`message`)}`);
+ }
});
```
diff --git a/en/application-dev/dfx/errormanager-guidelines.md b/en/application-dev/dfx/errormanager-guidelines.md
index a43d7c1fcec9042c6d8cbeb1287cebdddd3915d1..4679cfcfc78893590fe73eab770e49fc68a1a828 100644
--- a/en/application-dev/dfx/errormanager-guidelines.md
+++ b/en/application-dev/dfx/errormanager-guidelines.md
@@ -12,11 +12,11 @@ Application error management APIs are provided by the **errorManager** module. F
| API | Description |
| ------------------------------------------------------------ | ---------------------------------------------------- |
-| registerErrorObserver(observer: ErrorObserver): number | Registers an observer for application errors. A callback will be invoked when an application error is detected. This API works in a synchronous manner. The return value is the SN of the registered observer.|
-| unregisterErrorObserver(observerId: number, callback: AsyncCallback\): void | Unregisters an observer in callback mode. The number passed to this API is the SN of the registered observer. |
-| unregisterErrorObserver(observerId: number): Promise\ | Unregisters an observer in promise mode. The number passed to this API is the SN of the registered observer. |
+| on(type: "error", observer: ErrorObserver): number | Registers an observer for application errors. A callback will be invoked when an application error is detected. This API works in a synchronous manner. The return value is the SN of the registered observer.|
+| off(type: "error", observerId: number, callback: AsyncCallback\): void | Unregisters an observer in callback mode. The number passed to this API is the SN of the registered observer. |
+| off(type: "error", observerId: number): Promise\ | Unregisters an observer in promise mode. The number passed to this API is the SN of the registered observer. |
-When an asynchronous callback is used, the return value can be processed directly in the callback. If a promise is used, the return value can also be processed in the promise in a similar way. For details about the result codes, see [Result Codes for Unregistering an Observer](#result-codes-for-unregistering-an-observer).
+When an asynchronous callback is used, the return value can be processed directly in the callback. If a promise is used, the return value can also be processed in the promise in a similar way. For details about the result codes, see [Result Codes for Unregistering an Observer](#result codes-for-unregistering-an-observer).
**Table 2** Description of the ErrorObserver API
@@ -36,7 +36,7 @@ When an asynchronous callback is used, the return value can be processed directl
## Development Example
```ts
-import Ability from '@ohos.application.Ability'
+import UIAbility from '@ohos.app.ability.UIAbility';
import errorManager from '@ohos.app.ability.errorManager';
let registerId = -1;
@@ -45,15 +45,16 @@ let callback = {
console.log(errMsg);
}
}
-export default class MainAbility extends Ability {
+
+export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
- console.log("[Demo] MainAbility onCreate")
+ console.log("[Demo] EntryAbility onCreate")
registerId = errorManager.on("error", callback);
globalThis.abilityWant = want;
}
onDestroy() {
- console.log("[Demo] MainAbility onDestroy")
+ console.log("[Demo] EntryAbility onDestroy")
errorManager.off("error", registerId, (result) => {
console.log("[Demo] result " + result.code + ";" + result.message)
});
@@ -61,7 +62,7 @@ export default class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
// Main window is created for this ability.
- console.log("[Demo] MainAbility onWindowStageCreate")
+ console.log("[Demo] EntryAbility onWindowStageCreate")
windowStage.loadContent("pages/index", (err, data) => {
if (err.code) {
@@ -74,17 +75,17 @@ export default class MainAbility extends Ability {
onWindowStageDestroy() {
// Main window is destroyed to release UI resources.
- console.log("[Demo] MainAbility onWindowStageDestroy")
+ console.log("[Demo] EntryAbility onWindowStageDestroy")
}
onForeground() {
// Ability is brought to the foreground.
- console.log("[Demo] MainAbility onForeground")
+ console.log("[Demo] EntryAbility onForeground")
}
onBackground() {
// Ability is brought back to the background.
- console.log("[Demo] MainAbility onBackground")
+ console.log("[Demo] EntryAbility onBackground")
}
};
```
diff --git a/en/application-dev/reference/apis/js-apis-i18n.md b/en/application-dev/reference/apis/js-apis-i18n.md
index 02cebd741ce26bd61dd4a4282efcf2cc6d89ad08..2a85da3460cf4dff87a3076686a8b31ae136f65a 100644
--- a/en/application-dev/reference/apis/js-apis-i18n.md
+++ b/en/application-dev/reference/apis/js-apis-i18n.md
@@ -1,12 +1,12 @@
# @ohos.i18n (Internationalization)
- The **i18n** module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402.
-The [intl](js-apis-intl.md) module provides basic i18n capabilities through the standard i18n APIs defined in ECMA 402. It works with the i18n module to provide a complete suite of i18n capabilities.
+ This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402.
+The [Intl](js-apis-intl.md) module provides basic I18N capabilities through the standard I18N APIs defined in ECMA 402. It works with the I18N module to provide a complete suite of I18N capabilities.
> **NOTE**
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
-> - This module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. For details about the basic i18n capabilities, see [intl](js-apis-intl.md).
+> - This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402. For details about the basic I18N capabilities, see [Intl](js-apis-intl.md).
## Modules to Import
@@ -42,7 +42,7 @@ Obtains the localized script for the specified country.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -81,7 +81,7 @@ Obtains the localized script for the specified language.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -112,7 +112,7 @@ Obtains the list of system languages. For details about languages, see [Instanti
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -149,7 +149,7 @@ Obtains the list of countries and regions supported for the specified language.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -187,7 +187,7 @@ Checks whether the system language matches the specified region.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -218,7 +218,7 @@ Obtains the system language. For details about languages, see [Instantiating the
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -239,7 +239,7 @@ static setSystemLanguage(language: string): void
Sets the system language. Currently, this API does not support real-time updating of the system language.
-**System API**: This is a system API.
+This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
@@ -253,7 +253,7 @@ Sets the system language. Currently, this API does not support real-time updatin
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -284,7 +284,7 @@ Obtains the system region. For details about system regions, see [Instantiating
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -305,7 +305,7 @@ static setSystemRegion(region: string): void
Sets the system region.
-**System API**: This is a system API.
+This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
@@ -319,7 +319,7 @@ Sets the system region.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -350,7 +350,7 @@ Obtains the system locale. For details about system locales, see [Instantiating
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -371,7 +371,7 @@ static setSystemLocale(locale: string): void
Sets the system locale.
-**System API**: This is a system API.
+This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
@@ -385,7 +385,7 @@ Sets the system locale.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -416,7 +416,7 @@ Checks whether the 24-hour clock is used.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -437,7 +437,7 @@ static set24HourClock(option: boolean): void
Sets the 24-hour clock.
-**System API**: This is a system API.
+This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
@@ -451,7 +451,7 @@ Sets the 24-hour clock.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -473,7 +473,7 @@ static addPreferredLanguage(language: string, index?: number): void
Adds a preferred language to the specified position on the preferred language list.
-**System API**: This is a system API.
+This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
@@ -488,7 +488,7 @@ Adds a preferred language to the specified position on the preferred language li
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -512,7 +512,7 @@ static removePreferredLanguage(index: number): void
Deletes a preferred language from the specified position on the preferred language list.
-**System API**: This is a system API.
+This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
@@ -526,7 +526,7 @@ Deletes a preferred language from the specified position on the preferred langua
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -547,7 +547,7 @@ For details about the error codes, see [i18n Error Codes](../errorcodes/errorcod
static getPreferredLanguageList(): Array<string>
-Obtains the preferred language list.
+Obtains the list of preferred languages.
**System capability**: SystemCapability.Global.I18n
@@ -555,11 +555,11 @@ Obtains the preferred language list.
| Type | Description |
| ------------------- | --------- |
-| Array<string> | Preferred language list.|
+| Array<string> | List of preferred languages.|
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -590,7 +590,7 @@ Obtains the first language in the preferred language list.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -621,7 +621,7 @@ Obtains the preferred language of an application.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -642,7 +642,7 @@ static setUsingLocalDigit(flag: boolean): void
Specifies whether to enable use of local digits.
-**System API**: This is a system API.
+This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
@@ -652,11 +652,11 @@ Specifies whether to enable use of local digits.
| Name | Type | Mandatory | Description |
| ---- | ------- | ---- | ------------------------------- |
-| flag | boolean | Yes | Whether to enable the local digit switch. The value **true** means to enable the local digit switch, and the value **false** indicates the opposite.|
+| flag | boolean | Yes | Whether to turn on the local digit switch. The value **true** means to turn on the local digit switch, and the value **false** indicates the opposite.|
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -687,7 +687,7 @@ Checks whether use of local digits is enabled.
**Error codes**
-For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
+For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID | Error Message |
| ------ | ---------------------- |
@@ -1059,7 +1059,7 @@ Creates a **PhoneNumberFormat** object.
| Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | ---------------- |
| country | string | Yes | Country or region to which the phone number to be formatted belongs.|
-| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | No | Options of the **PhoneNumberFormat** object. |
+| options | [PhoneNumberFormatOptions](#phonenumberformatoptions9) | No | Options of the **PhoneNumberFormat** object. |
**Example**
```js
@@ -1149,7 +1149,7 @@ Obtains the home location of a phone number.
```
-## PhoneNumberFormatOptions8+
+## PhoneNumberFormatOptions9+
Defines the options for this PhoneNumberFormat object.
@@ -1194,7 +1194,7 @@ Creates an **IndexUtil** object.
**Example**
```js
- let indexUtil= I18n.getInstance("zh-CN");
+ let indexUtil = I18n.getInstance("zh-CN");
```
@@ -1267,7 +1267,7 @@ Obtains the index of a text object.
**Example**
```js
- let indexUtil= I18n.getInstance("zh-CN");
+ let indexUtil = I18n.getInstance("zh-CN");
let index = indexUtil.getIndex("hi"); // index = "H"
```
@@ -1382,7 +1382,7 @@ Puts the [BreakIterator](#breakiterator8) object to the first text boundary, whi
**Example**
```js
- let iterator = i18n.getLineInstance("en");
+ let iterator = I18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
let firstPos = iterator.first(); // firstPos = 0
```
@@ -1689,7 +1689,7 @@ Obtains the list of time zone city IDs supported by the system.
static getCityDisplayName(cityID: string, locale: string): string
-Obtains the localized representation of a time zone city in the specified locale.
+Obtains the localized display of a time zone city in the specified locale.
**System capability**: SystemCapability.Global.I18n
@@ -2363,7 +2363,7 @@ This API is supported since API version 8 and is deprecated since API version 9.
getPreferredLanguageList(): Array<string>
-Obtains the preferred language list.
+Obtains the list of preferred languages.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9) instead.
@@ -2373,7 +2373,7 @@ This API is supported since API version 8 and is deprecated since API version 9.
| Type | Description |
| ------------------- | --------- |
-| Array<string> | Preferred language list.|
+| Array<string> | List of preferred languages.|
**Example**
```js
diff --git a/en/application-dev/reference/apis/js-apis-intl.md b/en/application-dev/reference/apis/js-apis-intl.md
index 623695f1cc4c167bd984a408b5c2dde85ff42cf5..22b2225382e82166356b37003483c7c27a1400e0 100644
--- a/en/application-dev/reference/apis/js-apis-intl.md
+++ b/en/application-dev/reference/apis/js-apis-intl.md
@@ -67,7 +67,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).|
-| options9+ | [LocaleOptions](#localeoptions6) | No | Options for creating the **Locale** object. |
+| options9+ | [LocaleOptions](#localeoptions9) | No | Options for creating the **Locale** object. |
**Example**
```js
@@ -159,7 +159,7 @@ Minimizes information of the **Locale** object. If the script and locale informa
```
-## LocaleOptions6+
+## LocaleOptions9+
Represents the locale options.
@@ -206,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.|
-| options9+ | [DateTimeOptions](#datetimeoptions6) | No | Options for creating a **DateTimeFormat** object. |
+| options9+ | [DateTimeOptions](#datetimeoptions9) | No | Options for creating a **DateTimeFormat** object. |
**Example**
```js
@@ -298,7 +298,7 @@ Obtains the formatting options for **DateTimeFormat** object.
| Type | Description |
| ------------------------------------ | ----------------------------- |
-| [DateTimeOptions](#datetimeoptions6) | Formatting options for **DateTimeFormat** objects.|
+| [DateTimeOptions](#datetimeoptions9) | Formatting options for **DateTimeFormat** objects.|
**Example**
```js
@@ -310,7 +310,7 @@ Obtains the formatting options for **DateTimeFormat** object.
```
-## DateTimeOptions6+
+## DateTimeOptions9+
Provides the options for the **DateTimeFormat** object.
@@ -370,7 +370,7 @@ Creates a **NumberFormat** 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.|
-| options9+ | [NumberOptions](#numberoptions6) | No | Options for creating a **NumberFormat** object. |
+| options9+ | [NumberOptions](#numberoptions9) | No | Options for creating a **NumberFormat** object. |
**Example**
```js
@@ -420,7 +420,7 @@ Obtains the options of the **NumberFormat** object.
| Type | Description |
| -------------------------------- | --------------------------- |
-| [NumberOptions](#numberoptions6) | Formatting options for **NumberFormat** objects.|
+| [NumberOptions](#numberoptions9) | Formatting options for **NumberFormat** objects.|
**Example**
@@ -433,7 +433,7 @@ Obtains the options of the **NumberFormat** object.
```
-## NumberOptions6+
+## NumberOptions9+
Defines the device capability.
@@ -493,7 +493,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.|
-| options9+ | [CollatorOptions](#collatoroptions8) | No | Options for creating a **Collator** object. |
+| options9+ | [CollatorOptions](#collatoroptions9) | No | Options for creating a **Collator** object. |
**Example**
```js
@@ -544,7 +544,7 @@ Returns properties reflecting the locale and collation options of a **Collator**
| Type | Description |
| ------------------------------------ | ----------------- |
-| [CollatorOptions](#collatoroptions8) | Properties of the **Collator** object.|
+| [CollatorOptions](#collatoroptions9) | Properties of the **Collator** object.|
**Example**
```js
@@ -556,7 +556,7 @@ Returns properties reflecting the locale and collation options of a **Collator**
```
-## CollatorOptions8+
+## CollatorOptions9+
Represents the properties of a **Collator** object.
@@ -604,7 +604,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.|
-| options9+ | [PluralRulesOptions](#pluralrulesoptions8) | No | Options for creating a **PluralRules** object. |
+| options9+ | [PluralRulesOptions](#pluralrulesoptions9) | No | Options for creating a **PluralRules** object. |
**Example**
```js
@@ -647,7 +647,7 @@ Obtains a string that represents the singular-plural type of the specified numbe
```
-## PluralRulesOptions8+
+## PluralRulesOptions9+
Represents the properties of a **PluralRules** object.
@@ -695,7 +695,7 @@ Creates a **RelativeTimeFormat** object.
| Name | Type | Mandatory | Description |
| -------------------- | ---------------------------------------- | ---- | ---------------------------- |
| locale | string \| Array<string> | Yes | A string containing locale information, including the language, optional script, and region.|
-| options9+ | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions8) | No | Options for creating a **RelativeTimeFormat** object. |
+| options9+ | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions9) | No | Options for creating a **RelativeTimeFormat** object. |
**Example**
```js
@@ -787,7 +787,7 @@ Obtains the formatting options for **RelativeTimeFormat** objects.
```
-## RelativeTimeFormatInputOptions8+
+## RelativeTimeFormatInputOptions9+
Represents the properties of a **RelativeTimeFormat** object.
diff --git a/en/application-dev/reference/apis/js-apis-net-connection.md b/en/application-dev/reference/apis/js-apis-net-connection.md
index d5a5f1585a5ae153694833b611861cc49325c4e7..adb1c8ee47ae8dc076f5b2c2f00b2c2ca92a2cd5 100644
--- a/en/application-dev/reference/apis/js-apis-net-connection.md
+++ b/en/application-dev/reference/apis/js-apis-net-connection.md
@@ -1,8 +1,8 @@
# @ohos.net.connection (Network Connection Management)
-The **connection** module provides basic network management capabilities. You can obtain the default active data network or the list of all active data networks, enable or disable the airplane mode, and obtain network capability information.
+The network connection management module provides basic network management capabilities. You can obtain the default active data network or the list of all active data networks, enable or disable the airplane mode, and obtain network capability information.
-> **NOTE**
+> **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
@@ -10,6 +10,40 @@ The **connection** module provides basic network management capabilities. You ca
```js
import connection from '@ohos.net.connection'
```
+## connection.createNetConnection
+
+createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection
+
+Creates a **NetConnection** object. **netSpecifier** specifies the network, and **timeout** specifies the timeout interval in ms. **timeout** is configurable only when **netSpecifier** is specified. If neither of them is present, the default network is used.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
+| netSpecifier | [NetSpecifier](#netspecifier) | No | Network specifier. If this parameter is not set, the default network is used. |
+| timeout | number | No | Timeout interval for obtaining the network specified by **netSpecifier**. This parameter is valid only when **netSpecifier** is set.|
+
+**Return value**
+
+| Type | Description |
+| ------------------------------- | -------------------- |
+| [NetConnection](#netconnection) | Handle of the network specified by **netSpecifier**.|
+
+**Example**
+
+```js
+// Default network
+let netConnection = connection.createNetConnection()
+
+// Cellular network
+let netConnectionCellular = connection.createNetConnection({
+ netCapabilities: {
+ bearerTypes: [connection.NetBearType.BEARER_CELLULAR]
+ }
+})
+```
## connection.getDefaultNet
@@ -25,14 +59,22 @@ Obtains the default active data network. This API uses an asynchronous callback
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
-| callback | AsyncCallback\<[NetHandle](#nethandle)> | Yes | Callback used to return the result.|
+| callback | AsyncCallback\<[NetHandle](#nethandle)> | Yes | Callback used to return the result. If the default activated data network is obtained successfully, err is undefined and data is the default activated data network. Otherwise, err is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
-connection.getDefaultNet(function (error, netHandle) {
+connection.getDefaultNet(function (error, data) {
console.log(JSON.stringify(error))
- console.log(JSON.stringify(netHandle))
+ console.log(JSON.stringify(data))
})
```
@@ -52,17 +94,25 @@ Obtains the default active data network. This API uses a promise to return the r
| --------------------------------- | ------------------------------------- |
| Promise\<[NetHandle](#nethandle)> | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
-connection.getDefaultNet().then(function (netHandle) {
- console.log(JSON.stringify(netHandle))
+connection.getDefaultNet().then(function (data) {
+ console.log(JSON.stringify(data))
})
```
## connection.getDefaultNetSync9+
-getDefaultNetSync(): NetHandle;
+getDefaultNetSync(): NetHandle
Obtains the default active data network in synchronous mode. You can use [getNetCapabilities](#connectiongetnetcapabilities) to obtain information such as the network type and capabilities.
@@ -76,59 +126,321 @@ Obtains the default active data network in synchronous mode. You can use [getNet
| --------- | ---------------------------------- |
| NetHandle | Handle of the default active data network.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
let netHandle = connection.getDefaultNetSync();
```
+## connection.getGlobalHttpProxy10+
-## connection.hasDefaultNet
+getGlobalHttpProxy(callback: AsyncCallback\): void
-hasDefaultNet(callback: AsyncCallback\): void
+Obtains the global HTTP proxy configuration of the network. This API uses an asynchronous callback to return the result.
-Checks whether the default data network is activated. This API uses an asynchronous callback to return the result. You can use [getDefaultNet](#connectiongetdefaultnet) to obtain the default data network, if any.
+**System API**: This is a system API.
-**Required permission**: ohos.permission.GET_NETWORK_INFO
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| --------- | ------------------------------------------------------------ | ---- | ---------------- |
+| callback | AsyncCallback\<[HttpProxy](#httpproxy)> | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is obtained successfully, **err** is **undefined** and **data** is the global HTTP proxy configuration. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.getGlobalHttpProxy((error,data) => {
+ console.info(JSON.stringify(error));
+ console.info(JSON.stringify(data));
+})
+```
+
+## connection.getGlobalHttpProxy10+
+
+getGlobalHttpProxy(): Promise\;
+
+Obtains the global HTTP proxy configuration of the network. This API uses a promise to return the result.
+
+**System API**: This is a system API.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\<[HttpProxy](#httpproxy)> | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.getGlobalHttpProxy().then((data) => {
+ console.info(JSON.stringify(data));
+}).catch(error => {
+ console.info(JSON.stringify(error));
+})
+```
+
+## connection.setGlobalHttpProxy10+
+
+setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\): void
+
+Sets the global HTTP proxy configuration of the network. This API uses an asynchronous callback to return the result.
+
+**System API**: This is a system API.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
-| Name | Type | Mandatory| Description |
-| -------- | ----------------------- | ---- | -------------------------------------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** indicates that the default data network is activated.|
+| Name | Type | Mandatory| Description |
+| --------- | ------------------------------------------------------------ | ---- | ---------------- |
+| httpProxy | [HttpProxy](#httpproxy) | Yes | Global HTTP proxy configuration of the network.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is set successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
-connection.hasDefaultNet(function (error, has) {
- console.log(JSON.stringify(error))
- console.log('has: ' + has)
+let exclusionStr="192.168,baidu.com"
+let exclusionArray = exclusionStr.split(',');
+let httpProxy = {
+ host: "192.168.xx.xxx",
+ port: 8080,
+ exclusionList: exclusionArray
+}
+connection.setGlobalHttpProxy(httpProxy, (error, data) => {
+ console.info(JSON.stringify(error));
+ console.info(JSON.stringify(data));
+});
+```
+
+## connection.setGlobalHttpProxy10+
+
+setGlobalHttpProxy(httpProxy: HttpProxy): Promise\;
+
+Sets the global HTTP proxy configuration of the network. This API uses a promise to return the result.
+
+**System API**: This is a system API.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| --------- | ------------------------------------------------------------ | ---- | ---------------- |
+| httpProxy | [HttpProxy](#httpproxy) | Yes | Global HTTP proxy configuration of the network.|
+
+**Return value**
+
+| Type | Description |
+| ------------------------------------------- | ----------------------------- |
+| Promise\ | Promise that returns no value.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let exclusionStr="192.168,baidu.com"
+let exclusionArray = exclusionStr.split(',');
+let httpProxy = {
+ host: "192.168.xx.xxx",
+ port: 8080,
+ exclusionList: exclusionArray
+}
+connection.setGlobalHttpProxy(httpProxy).then((error, data) => {
+ console.info(JSON.stringify(data));
+}).catch(error=>{
+ console.info(JSON.stringify(error));
})
```
-## connection.hasDefaultNet
+## connection.getAppNet9+
-hasDefaultNet(): Promise\
+getAppNet(callback: AsyncCallback\): void
-Checks whether the default data network is activated. This API uses a promise to return the result. You can use [getDefaultNet](#connectiongetdefaultnet) to obtain the default data network, if any.
+Obtains information about the network bound to an application. This API uses an asynchronous callback to return the result.
-**Required permission**: ohos.permission.GET_NETWORK_INFO
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| --------- | ------------------------------------------------------------ | ---- | ---------------- |
+| callback | AsyncCallback\<[NetHandle](#nethandle)> | Yes | Callback used to return the result. If information about the network bound to the application is successfully obtained, **err** is **undefined** and **data** is the obtained network information. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.getAppNet(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+```
+
+## connection.getAppNet9+
+
+getAppNet(): Promise\;
+
+Obtains information about the network bound to an application. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
-| Type | Description |
-| ----------------- | ----------------------------------------------- |
-| Promise\ | Promise used to return the result. The value **true** indicates that the default data network is activated.|
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\<[NetHandle](#nethandle)> | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.getAppNet().then((data) => {
+ console.info(JSON.stringify(data));
+}).catch(error => {
+ console.info(JSON.stringify(error));
+})
+```
+
+## connection.SetAppNet9+
+
+setAppNet(netHandle: NetHandle, callback: AsyncCallback\): void
+
+Binds an application to the specified network, so that the application can access the external network only through this network. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.INTERNET
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| --------- | ------------------------------------------------------------ | ---- | ---------------- |
+| netHandle | [NetHandle](#nethandle) | Yes | Handle of the data network.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If the application is successfully bound to the specified network, **err** is **undefined**. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
-connection.hasDefaultNet().then(function (has) {
- console.log('has: ' + has)
+connection.getDefaultNet(function (error, netHandle) {
+ connection.setAppNet(netHandle, (error, data) => {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+ });
+})
+```
+
+## connection.SetAppNet9+
+
+setAppNet(netHandle: NetHandle): Promise\;
+
+Binds an application to the specified network, so that the application can access the external network only through this network. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.INTERNET
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| --------- | ------------------------------------------------------------ | ---- | ---------------- |
+| netHandle | [NetHandle](#nethandle) | Yes | Handle of the data network.|
+
+**Return value**
+
+| Type | Description |
+| ------------------------------------------- | ----------------------------- |
+| Promise\ | Promise that returns no value.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.getDefaultNet().then(function (netHandle) {
+ connection.setAppNet(netHandle).then((error, data) => {
+ console.log(JSON.stringify(data))
+ }).catch(error => {
+ console.log(JSON.stringify(error))
+ })
})
```
@@ -136,7 +448,7 @@ connection.hasDefaultNet().then(function (has) {
getAllNets(callback: AsyncCallback<Array<NetHandle>>): void
-Obtains the list of all active data networks. This API uses an asynchronous callback to return the result.
+Obtains the list of all connected networks. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
@@ -146,23 +458,30 @@ Obtains the list of all active data networks. This API uses an asynchronous call
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| callback | AsyncCallback<Array<[NetHandle](#nethandle)>> | Yes| Callback used to return the result.|
+| callback | AsyncCallback<Array<[NetHandle](#nethandle)>> | Yes| Callback used to return the result. If the list of all connected networks is obtained successfully, **err** is **undefined** and **data** is the list of activated data networks. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
-connection.getAllNets(function (error, nets) {
+connection.getAllNets(function (error, data) {
console.log(JSON.stringify(error))
- console.log(JSON.stringify(nets))
+ console.log(JSON.stringify(data))
});
```
-
## connection.getAllNets
getAllNets(): Promise<Array<NetHandle>>
-Obtains the list of all active data networks. This API uses a promise to return the result.
+Obtains the list of all connected networks. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
@@ -174,11 +493,19 @@ Obtains the list of all active data networks. This API uses a promise to return
| -------- | -------- |
| Promise<Array<[NetHandle](#nethandle)>> | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
-connection.getAllNets().then(function (nets) {
- console.log(JSON.stringify(nets))
+connection.getAllNets().then(function (data) {
+ console.log(JSON.stringify(data))
});
```
@@ -186,7 +513,7 @@ connection.getAllNets().then(function (nets) {
getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback\): void
-Obtains connection properties of the network corresponding to the given network handle. This API uses an asynchronous callback to return the result.
+Obtains connection properties of the network corresponding to the **netHandle**. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
@@ -197,15 +524,25 @@ Obtains connection properties of the network corresponding to the given network
| Name | Type | Mandatory| Description |
| --------- | ------------------------------------------------------------ | ---- | ---------------- |
| netHandle | [NetHandle](#nethandle) | Yes | Handle of the data network.|
-| callback | AsyncCallback\<[ConnectionProperties](#connectionproperties)> | Yes | Callback used to return the result. |
+| callback | AsyncCallback\<[ConnectionProperties](#connectionproperties)> | Yes | Callback used to return the result. If the connection properties of the network corresponding to the **netHandle** is obtained successfully, **err** is **undefined** and **data** is the obtained network connection information. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
connection.getDefaultNet().then(function (netHandle) {
- connection.getConnectionProperties(netHandle, function (error, info) {
+ connection.getConnectionProperties(netHandle, function (error, data) {
console.log(JSON.stringify(error))
- console.log(JSON.stringify(info))
+ console.log(JSON.stringify(data))
})
})
```
@@ -214,7 +551,7 @@ connection.getDefaultNet().then(function (netHandle) {
getConnectionProperties(netHandle: NetHandle): Promise\
-Obtains connection properties of the network corresponding to **netHandle**. This API uses a promise to return the result.
+Obtains connection properties of the network corresponding to the **netHandle**. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
@@ -232,12 +569,22 @@ Obtains connection properties of the network corresponding to **netHandle**. Thi
| ------------------------------------------------------- | --------------------------------- |
| Promise\<[ConnectionProperties](#connectionproperties)> | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
connection.getDefaultNet().then(function (netHandle) {
- connection.getConnectionProperties(netHandle).then(function (info) {
- console.log(JSON.stringify(info))
+ connection.getConnectionProperties(netHandle).then(function (data) {
+ console.log(JSON.stringify(data))
})
})
```
@@ -246,7 +593,7 @@ connection.getDefaultNet().then(function (netHandle) {
getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback\): void
-Obtains capability information of the network corresponding to **netHandle**. This API uses an asynchronous callback to return the result.
+Obtains capability information of the network corresponding to the **netHandle**. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
@@ -257,15 +604,25 @@ Obtains capability information of the network corresponding to **netHandle**. Th
| Name | Type | Mandatory| Description |
| --------- | --------------------------------------------------- | ---- | ---------------- |
| netHandle | [NetHandle](#nethandle) | Yes | Handle of the data network.|
-| callback | AsyncCallback\<[NetCapabilities](#netcapabilities)> | Yes | Callback used to return the result. |
+| callback | AsyncCallback\<[NetCapabilities](#netcapabilities)> | Yes | Callback used to return the result. If the capability information of the network corresponding to the **netHandle** is obtained successfully, **err** is **undefined** and **data** is the obtained network capability information. Otherwise, **err** is an error object. |
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
connection.getDefaultNet().then(function (netHandle) {
- connection.getNetCapabilities(netHandle, function (error, info) {
+ connection.getNetCapabilities(netHandle, function (error, data) {
console.log(JSON.stringify(error))
- console.log(JSON.stringify(info))
+ console.log(JSON.stringify(data))
})
})
```
@@ -274,7 +631,7 @@ connection.getDefaultNet().then(function (netHandle) {
getNetCapabilities(netHandle: NetHandle): Promise\
-Obtains capability information of the network corresponding to **netHandle**. This API uses a promise to return the result.
+Obtains capability information of the network corresponding to the **netHandle**. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
@@ -292,12 +649,22 @@ Obtains capability information of the network corresponding to **netHandle**. Th
| --------------------------------------------- | --------------------------------- |
| Promise\<[NetCapabilities](#netcapabilities)> | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
connection.getDefaultNet().then(function (netHandle) {
- connection.getNetCapabilities(netHandle).then(function (info) {
- console.log(JSON.stringify(info))
+ connection.getNetCapabilities(netHandle).then(function (data) {
+ console.log(JSON.stringify(data))
})
})
```
@@ -318,12 +685,20 @@ Checks whether the data traffic usage on the current network is metered. This AP
| -------- | ----------------------- | ---- | -------------------------------------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** indicates the data traffic usage is metered.|
-**Example**:
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
```js
-connection.isDefaultNetMetered(function (error, has) {
+connection.isDefaultNetMetered(function (error, data) {
console.log(JSON.stringify(error))
- console.log('has: ' + has)
+ console.log('data: ' + data)
})
```
@@ -343,11 +718,216 @@ Checks whether the data traffic usage on the current network is metered. This AP
| ----------------- | ----------------------------------------------- |
| Promise\ | Promise used to return the result. The value **true** indicates the data traffic usage is metered.|
-**Example**:
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.isDefaultNetMetered().then(function (data) {
+ console.log('data: ' + data)
+})
+```
+
+## connection.hasDefaultNet
+
+hasDefaultNet(callback: AsyncCallback\): void
+
+Checks whether the default data network is activated. This API uses an asynchronous callback to return the result. You can use [getDefaultNet](#connectiongetdefaultnet) to obtain the default data network, if any.
+
+**Required permission**: ohos.permission.GET_NETWORK_INFO
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | ----------------------- | ---- | -------------------------------------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** indicates the default data network is activated.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.hasDefaultNet(function (error, data) {
+ console.log(JSON.stringify(error))
+ console.log('data: ' + data)
+})
+```
+
+## connection.hasDefaultNet
+
+hasDefaultNet(): Promise\
+
+Checks whether the default data network is activated. This API uses a promise to return the result. You can use [getDefaultNet](#connectiongetdefaultnet) to obtain the default data network, if any.
+
+**Required permission**: ohos.permission.GET_NETWORK_INFO
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Return value**
+
+| Type | Description |
+| ----------------- | ----------------------------------------------- |
+| Promise\ | Promise used to return the result. The value **true** indicates that the default data network is activated.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
```js
-connection.isDefaultNetMetered().then(function (has) {
- console.log('has: ' + has)
+connection.hasDefaultNet().then(function (data) {
+ console.log('data: ' + data)
+})
+```
+
+## connection.enableAirplaneMode
+
+enableAirplaneMode(callback: AsyncCallback\): void
+
+Enables the airplane mode. This API uses an asynchronous callback to return the result.
+
+**System API**: This is a system API.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------------------------------- | ---- | ------------------ |
+| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.enableAirplaneMode(function (error) {
+ console.log(JSON.stringify(error))
+})
+```
+
+## connection.enableAirplaneMode
+
+enableAirplaneMode(): Promise\
+
+Enables the airplane mode. This API uses a promise to return the result.
+
+**System API**: This is a system API.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Return value**
+
+| Type | Description |
+| ------------------------------------------- | ----------------------------- |
+| Promise\ | Promise that returns no value.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.enableAirplaneMode().then(function (error) {
+ console.log(JSON.stringify(error))
+})
+```
+
+## connection.disableAirplaneMode
+
+disableAirplaneMode(callback: AsyncCallback\): void
+
+Disables the airplane mode. This API uses an asynchronous callback to return the result.
+
+**System API**: This is a system API.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | ------------------------------------------------- | ---- | ------------------ |
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If the airplane mode is disabled successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.disableAirplaneMode(function (error) {
+ console.log(JSON.stringify(error))
+})
+```
+
+## connection.disableAirplaneMode
+
+disableAirplaneMode(): Promise\
+
+Disables the airplane mode. This API uses a promise to return the result.
+
+**System API**: This is a system API.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Return value**
+
+| Type | Description |
+| ------------------------------------------- | ----------------------------- |
+| Promise\ | Promise that returns no value.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+connection.disableAirplaneMode().then(function (error) {
+ console.log(JSON.stringify(error))
})
```
@@ -355,9 +935,8 @@ connection.isDefaultNetMetered().then(function (has) {
reportNetConnected(netHandle: NetHandle, callback: AsyncCallback<void>): void
-Reports connection of the data network. This API uses an asynchronous callback to return the result.
-
-If this API is called, the application considers that the network connection state (**ohos.net.connection.NetCap.NET_CAPABILITY_VAILDATED**) is inconsistent with that in the network management module.
+Reports a **netAavailable** event to NetManager. If this API is called, the application considers that its network status (ohos.net.connection.NetCap.NET_CAPABILITY_VAILDATED) is inconsistent with that of NetManager.
+This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET
@@ -368,7 +947,17 @@ If this API is called, the application considers that the network connection sta
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| netHandle | [NetHandle](#nethandle) | Yes| Handle of the data network. For details, see [NetHandle](#nethandle).|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the network status is reported successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
@@ -384,9 +973,8 @@ connection.getDefaultNet().then(function (netHandle) {
reportNetConnected(netHandle: NetHandle): Promise<void>
-Reports connection of the data network. This API uses a promise to return the result.
-
-If this API is called, the application considers that the network connection state (**ohos.net.connection.NetCap.NET_CAPABILITY_VAILDATED**) is inconsistent with that in the network management module.
+Reports a **netAavailable** event to NetManager. If this API is called, the application considers that its network status (ohos.net.connection.NetCap.NET_CAPABILITY_VAILDATED) is inconsistent with that of NetManager.
+This API uses a promise to return the result.
**Permission required**: ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET
@@ -399,11 +987,20 @@ If this API is called, the application considers that the network connection sta
| netHandle | [NetHandle](#nethandle) | Yes| Handle of the data network. For details, see [NetHandle](#nethandle).|
**Return value**
-
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
@@ -414,14 +1011,12 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
-
## connection.reportNetDisconnected
reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback<void>): void
-Reports disconnection of the data network. This API uses an asynchronous callback to return the result.
-
-If this API is called, the application considers that the network connection state (**ohos.net.connection.NetCap.NET_CAPABILITY_VAILDATED**) is inconsistent with that in the network management module.
+Reports a **netAavailable** event to NetManager. If this API is called, the application considers that its network status (ohos.net.connection.NetCap.NET_CAPABILITY_VAILDATED) is inconsistent with that of NetManager.
+This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET
@@ -432,7 +1027,17 @@ If this API is called, the application considers that the network connection sta
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| netHandle | [NetHandle](#nethandle) | Yes| Handle of the data network. For details, see [NetHandle](#nethandle).|
-| callback | AsyncCallback<void> | Yes| Callback used to return the result.|
+| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the network status is reported successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
@@ -444,14 +1049,12 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
-
## connection.reportNetDisconnected
reportNetDisconnected(netHandle: NetHandle): Promise<void>
-Reports disconnection of the data network. This API uses a promise to return the result.
-
-If this API is called, the application considers that the network connection state (**ohos.net.connection.NetCap.NET_CAPABILITY_VAILDATED**) is inconsistent with that in the network management module.
+Reports a **netAavailable** event to NetManager. If this API is called, the application considers that its network status (ohos.net.connection.NetCap.NET_CAPABILITY_VAILDATED) is inconsistent with that of NetManager.
+This API uses a promise to return the result.
**Permission required**: ohos.permission.GET_NETWORK_INFO and ohos.permission.INTERNET
@@ -464,11 +1067,20 @@ If this API is called, the application considers that the network connection sta
| netHandle | [NetHandle](#nethandle) | Yes| Handle of the data network. For details, see [NetHandle](#nethandle).|
**Return value**
-
| Type| Description|
| -------- | -------- |
| Promise<void> | Promise that returns no value.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
@@ -493,213 +1105,185 @@ Resolves the host name by using the default network to obtain all IP addresses.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------ |
-| host | string | Yes | Host name to be resolved.|
-| callback | AsyncCallback\> | Yes | Callback used to return the result. |
-
-**Example**
-
-```js
-let host = "xxxx";
-connection.getAddressesByName(host, function (error, addresses) {
- console.log(JSON.stringify(error))
- console.log(JSON.stringify(addresses))
-})
-```
-
-## connection.getAddressesByName
-
-getAddressesByName(host: string): Promise\>
-
-Resolves the host name by using the default network to obtain all IP addresses. This API uses a promise to return the result.
-
-**Required permission**: ohos.permission.GET_NETWORK_INFO
-
-**System capability**: SystemCapability.Communication.NetManager.Core
-
-**Parameters**
-
-| Name| Type | Mandatory| Description |
-| ------ | ------ | ---- | ------------------ |
-| host | string | Yes | Host name to be resolved.|
-
-**Return value**
-
-| Type | Description |
-| ------------------------------------------- | ----------------------------- |
-| Promise\> | Promise used to return the result.|
-
-**Example**
-
-```js
-let host = "xxxx";
-connection.getAddressesByName(host).then(function (addresses) {
- console.log(JSON.stringify(addresses))
-})
-```
-
-## connection.enableAirplaneMode
-
-enableAirplaneMode(callback: AsyncCallback\): void
-
-Enables the airplane mode. This API uses an asynchronous callback to return the result.
-
-**System API**: This is a system API.
-
-**System capability**: SystemCapability.Communication.NetManager.Core
-
-**Parameters**
-
-| Name | Type | Mandatory| Description |
-| -------- | ------------------------------------------------- | ---- | ------------------ |
-| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+| host | string | Yes | Host name to resolve.|
+| callback | AsyncCallback\> | Yes | Callback used to return the result. If all IP addresses are successfully obtained, **err** is **undefined**, and **data** is the list of all obtained IP addresses. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
-connection.enableAirplaneMode(function (error) {
+let host = "xxxx";
+connection.getAddressesByName(host, function (error, data) {
console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
})
```
-## connection.enableAirplaneMode
+## connection.getAddressesByName
-enableAirplaneMode(): Promise\
+getAddressesByName(host: string): Promise\>
-Enables the airplane mode. This API uses a promise to return the result.
+Resolves the host name by using the default network to obtain all IP addresses. This API uses a promise to return the result.
-**System API**: This is a system API.
+**Required permission**: ohos.permission.GET_NETWORK_INFO
+
+**System capability**: SystemCapability.Communication.NetManager.Core
-**System capability**: SystemCapability.Communication.NetManager.Core
+**Parameters**
+
+| Name| Type | Mandatory| Description |
+| ------ | ------ | ---- | ------------------ |
+| host | string | Yes | Host name to resolve.|
**Return value**
| Type | Description |
| ------------------------------------------- | ----------------------------- |
-| Promise\ | Promise that returns no value.|
+| Promise\> | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
-connection.enableAirplaneMode().then(function (error) {
- console.log(JSON.stringify(error))
+let host = "xxxx";
+connection.getAddressesByName(host).then(function (data) {
+ console.log(JSON.stringify(data))
})
```
-## connection.disableAirplaneMode
-
-disableAirplaneMode(callback: AsyncCallback\): void
-
-Disables the airplane mode. This API uses an asynchronous callback to return the result.
-
-**System API**: This is a system API.
-
-**System capability**: SystemCapability.Communication.NetManager.Core
+## NetConnection
-**Parameters**
+Represents the network connection handle.
-| Name | Type | Mandatory| Description |
-| -------- | ------------------------------------------------- | ---- | ------------------ |
-| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+### register
-**Example**
+register(callback: AsyncCallback\): void
-```js
-connection.disableAirplaneMode(function (error) {
- console.log(JSON.stringify(error))
-})
-```
+Registers a listener for network status changes.
-## connection.disableAirplaneMode
+**Required permission**: ohos.permission.GET_NETWORK_INFO
-disableAirplaneMode(): Promise\
+**System capability**: SystemCapability.Communication.NetManager.Core
-Disables the airplane mode. This API uses a promise to return the result.
+**Parameters**
-**System API**: This is a system API.
+| Name | Type | Mandatory| Description |
+| -------- | -------------------- | ---- | ---------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If a listener for network status changes is registered successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
-**System capability**: SystemCapability.Communication.NetManager.Core
+**Error codes**
-**Return value**
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+| 2101008 | The callback is not exists. |
+| 2101022 | The number of requests exceeded the maximum. |
-| Type | Description |
-| ------------------------------------------- | ----------------------------- |
-| Promise\ | Promise that returns no value.|
**Example**
```js
-connection.disableAirplaneMode().then(function (error) {
+netConnection.register(function (error) {
console.log(JSON.stringify(error))
})
```
-## connection.createNetConnection
+### unregister
-createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection
+unregister(callback: AsyncCallback\): void
-Obtains the handle of the network specified by **netSpecifier**.
+Unregisters the listener for network status changes.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
-| Name | Type | Mandatory| Description |
-| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
-| netSpecifier | [NetSpecifier](#netspecifier) | No | Network specifier. If this parameter is not set, the default network is used. |
-| timeout | number | No | Timeout interval for obtaining the network specified by **netSpecifier**. This parameter is valid only when **netSpecifier** is set.|
+| Name | Type | Mandatory| Description |
+| -------- | -------------------- | ---- | ---------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If a listener for network status changes is unregistered successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
-**Return value**
+**Error codes**
-| Type | Description |
-| ------------------------------- | -------------------- |
-| [NetConnection](#netconnection) | Handle of the network specified by **netSpecifier**.|
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+| 2101007 | The same callback exists. |
**Example**
```js
-// Default network
-let netConnection = connection.createNetConnection()
-
-// Cellular network
-let netConnectionCellular = connection.createNetConnection({
- netCapabilities: {
- bearerTypes: [connection.NetBearType.BEARER_CELLULAR]
- }
+netConnection.unregister(function (error) {
+ console.log(JSON.stringify(error))
})
```
-## NetConnection
-
-Represents the network connection handle.
-
### on('netAvailable')
on(type: 'netAvailable', callback: Callback\): void
Registers a listener for **netAvailable** events.
+**Model restriction**: Before you call this API, make sure that you have called **register** to add a listener and called **unregister** API to unsubscribe from status changes of the default network.
+
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
-| type | string | Yes | Event type. The value is fixed at **netAvailable**.
**netAvailable**: event indicating that the data network is available.|
-| callback | Callback\<[NetHandle](#nethandle)> | Yes | Callback used to return the result. |
+| type | string | Yes | Event type. The value is fixed to **netAvailable**.
**netAvailable**: event indicating that the data network is available.|
+| callback | Callback\<[NetHandle](#nethandle)> | Yes | Callback used to return the network handle.|
**Example**
```js
-netConnection.on('netAvailable', function (data) {
+// Create a NetConnection object.
+let netCon = connection.createNetConnection()
+
+// Call register to register a listener.
+netCon.register(function (error) {
+ console.log(JSON.stringify(error))
+})
+
+// Subscribe to netAvailable events. Event notifications can be received only after register is called.
+netCon.on('netAvailable', function (data) {
console.log(JSON.stringify(data))
})
+
+// Call unregister to unregister the listener.
+netCon.unregister(function (error) {
+ console.log(JSON.stringify(error))
+})
```
-### on('netCapabilitiesChange')
+### on('netBlockStatusChange')
-on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, netCap: NetCapabilities }>): void
+on(type: 'netBlockStatusChange', callback: Callback<{ netHandle: NetHandle, blocked: boolean }>): void
-Registers a listener for **netCapabilitiesChange** events.
+Registers a listener for **netBlockStatusChange** events.
+
+**Model restriction**: Before you call this API, make sure tat you have called **register** to add a listener and called **unregister** API to unsubscribe from status changes of the default network.
**System capability**: SystemCapability.Communication.NetManager.Core
@@ -707,22 +1291,38 @@ Registers a listener for **netCapabilitiesChange** events.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| type | string | Yes | Event type. The value is fixed at **netCapabilitiesChange**.
**netCapabilitiesChange**: event indicating that network capabilities have changed.|
-| callback | Callback<{ netHandle: [NetHandle](#nethandle), netCap: [NetCapabilities](#netcapabilities) }> | Yes | Callback used to return the result. |
+| type | string | Yes | Event type. The value is fixed to **netBlockStatusChange**.
**netBlockStatusChange**: event indicating a change in the network blocking status.|
+| callback | Callback<{ netHandle: [NetHandle](#nethandle), blocked: boolean }> | Yes | Callback used to return the network handle (**netHandle**) and network status (**blocked**).|
**Example**
```js
-netConnection.on('netCapabilitiesChange', function (data) {
+// Create a NetConnection object.
+let netCon = connection.createNetConnection()
+
+// Call register to register a listener.
+netCon.register(function (error) {
+ console.log(JSON.stringify(error))
+})
+
+// Subscribe to netBlockStatusChange events. Event notifications can be received only after register is called.
+netCon.on('netBlockStatusChange', function (data) {
console.log(JSON.stringify(data))
})
+
+// Call unregister to unregister the listener.
+netCon.unregister(function (error) {
+ console.log(JSON.stringify(error))
+})
```
-### on('netConnectionPropertiesChange')
+### on('netCapabilitiesChange')
-on(type: 'netConnectionPropertiesChange', callback: Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }>): void
+on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, netCap: NetCapabilities }>): void
-Registers a listener for **netConnectionPropertiesChange** events.
+Registers a listener for **netCapabilitiesChange** events.
+
+**Model restriction**: Before you call this API, make sure tat you have called **register** to add a listener and called **unregister** API to unsubscribe from status changes of the default network.
**System capability**: SystemCapability.Communication.NetManager.Core
@@ -730,22 +1330,38 @@ Registers a listener for **netConnectionPropertiesChange** events.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| type | string | Yes | Event type. The value is fixed at **netConnectionPropertiesChange**.
**netConnectionPropertiesChange**: event indicating that network connection properties have changed.|
-| callback | Callback<{ netHandle: [NetHandle](#nethandle), connectionProperties: [ConnectionProperties](#connectionproperties) }> | Yes | Callback used to return the result. |
+| type | string | Yes | Event type. The value is fixed to **netCapabilitiesChange**.
**netCapabilitiesChange**: event indicating that the network capabilities have changed.|
+| callback | Callback<{ netHandle: [NetHandle](#nethandle), netCap: [NetCapabilities](#netcapabilities) }> | Yes | Callback used to return the network handle (**netHandle**) and capability information (**netCap**).|
**Example**
```js
-netConnection.on('netConnectionPropertiesChange', function (data) {
+// Create a NetConnection object.
+let netCon = connection.createNetConnection()
+
+// Call register to register a listener.
+netCon.register(function (error) {
+ console.log(JSON.stringify(error))
+})
+
+// Subscribe to netCapabilitiesChange events. Event notifications can be received only after register is called.
+netCon.on('netCapabilitiesChange', function (data) {
console.log(JSON.stringify(data))
})
+
+// Call unregister to unregister the listener.
+netCon.unregister(function (error) {
+ console.log(JSON.stringify(error))
+})
```
-### on('netBlockStatusChange')
+### on('netConnectionPropertiesChange')
-on(type: 'netBlockStatusChange', callback: Callback<{ netHandle: NetHandle, blocked: boolean }>): void
+on(type: 'netConnectionPropertiesChange', callback: Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }>): void
-Registers a listener for **netBlockStatusChange** events.
+Registers a listener for **netConnectionPropertiesChange** events.
+
+**Model restriction**: Before you call this API, make sure tat you have called **register** to add a listener and called **unregister** API to unsubscribe from status changes of the default network.
**System capability**: SystemCapability.Communication.NetManager.Core
@@ -753,15 +1369,29 @@ Registers a listener for **netBlockStatusChange** events.
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| type | string | Yes | Event type. The value is fixed at **netBlockStatusChange**.
**netBlockStatusChange**: event indicating a change in the network blocking status.|
-| callback | Callback<{ netHandle: [NetHandle](#nethandle), blocked: boolean }> | Yes | Callback used to return the result. |
+| type | string | Yes | Event type. The value is fixed to **netConnectionPropertiesChange**.
**netConnectionPropertiesChange**: event indicating that network connection properties have changed.|
+| callback | Callback<{ netHandle: [NetHandle](#nethandle), connectionProperties: [ConnectionProperties](#connectionproperties) }> | Yes | Callback used to return the network handle (**netHandle**) and capability information (**netCap**).|
**Example**
```js
-netConnection.on('netBlockStatusChange', function (data) {
+// Create a NetConnection object.
+let netCon = connection.createNetConnection()
+
+// Call register to register a listener.
+netCon.register(function (error) {
+ console.log(JSON.stringify(error))
+})
+
+// Subscribe to netConnectionPropertiesChange events. Event notifications can be received only after register is called.
+netCon.on('netConnectionPropertiesChange', function (data) {
console.log(JSON.stringify(data))
})
+
+// Call unregister to unregister the listener.
+netCon.unregister(function (error) {
+ console.log(JSON.stringify(error))
+})
```
### on('netLost')
@@ -770,22 +1400,37 @@ on(type: 'netLost', callback: Callback\): void
Registers a listener for **netLost** events.
+**Model restriction**: Before you call this API, make sure tat you have called **register** to add a listener and called **unregister** API to unsubscribe from status changes of the default network.
+
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
-| type | string | Yes | Event type. The value is fixed at **netLost**.
netLost: event indicating that the network is interrupted or normally disconnected.|
-| callback | Callback\<[NetHandle](#nethandle)> | Yes | Callback used to return the result. |
+| type | string | Yes | Event type. The value is fixed to **netLost**.
netLost: event indicating that the network is interrupted or normally disconnected.|
+| callback | Callback\<[NetHandle](#nethandle)> | Yes | Callback used to return the network handle (**netHandle**).|
**Example**
```js
-let netConnection1 = connection.createNetConnection()
-netConnection1.on('netLost', function (data) {
+// Create a NetConnection object.
+let netCon = connection.createNetConnection()
+
+// Call register to register a listener.
+netCon.register(function (error) {
+ console.log(JSON.stringify(error))
+})
+
+// Subscribe to netLost events. Event notifications can be received only after register is called.
+netCon.on('netLost', function (data) {
console.log(JSON.stringify(data))
})
+
+// Call unregister to unregister the listener.
+netCon.unregister(function (error) {
+ console.log(JSON.stringify(error))
+})
```
### on('netUnavailable')
@@ -794,65 +1439,35 @@ on(type: 'netUnavailable', callback: Callback\): void
Registers a listener for **netUnavailable** events.
+**Model restriction**: Before you call this API, make sure tat you have called **register** to add a listener and called **unregister** API to unsubscribe from status changes of the default network.
+
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------- | ---- | ------------------------------------------------------------ |
-| type | string | Yes | Event type. The value is fixed at **netUnavailable**.
**netUnavailable**: event indicating that the network is unavailable.|
-| callback | Callback\ | Yes | Callback used to return the result. |
+| type | string | Yes | Event type. The value is fixed to **netUnavailable**.
**netUnavailable**: event indicating that the network is unavailable.|
+| callback | Callback\ | Yes | Callback used to return the result, which is empty.|
**Example**
```js
-netConnection.on('netUnavailable', function (data) {
- console.log(JSON.stringify(data))
-})
-```
-
-### register
-
-register(callback: AsyncCallback\): void
-
-Registers a listener for network status changes.
-
-**Required permission**: ohos.permission.GET_NETWORK_INFO
-
-**System capability**: SystemCapability.Communication.NetManager.Core
-
-**Parameters**
-
-| Name | Type | Mandatory| Description |
-| -------- | -------------------- | ---- | ---------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+// Create a NetConnection object.
+let netCon = connection.createNetConnection()
-**Example**
-
-```js
-netConnection.register(function (error) {
+// Call register to register a listener.
+netCon.register(function (error) {
console.log(JSON.stringify(error))
})
-```
-
-### unregister
-
-unregister(callback: AsyncCallback\): void
-
-Unregisters the listener for network status changes.
-
-**System capability**: SystemCapability.Communication.NetManager.Core
-
-**Parameters**
-
-| Name | Type | Mandatory| Description |
-| -------- | -------------------- | ---- | ---------- |
-| callback | AsyncCallback\ | Yes | Callback used to return the result.|
-**Example**
+// Subscribe to netUnavailable events. Event notifications can be received only after register is called.
+netCon.on('netUnavailable', function (data) {
+ console.log(JSON.stringify(data))
+})
-```js
-netConnection.unregister(function (error) {
+// Call unregister to unregister the listener.
+netCon.unregister(function (error) {
console.log(JSON.stringify(error))
})
```
@@ -861,24 +1476,22 @@ netConnection.unregister(function (error) {
Defines the handle of the data network.
-Before invoking NetHandle APIs, call **getNetHandle** to obtain a **NetHandle** object.
+Before invoking **NetHandle** APIs, call **getNetHandle** to obtain a **NetHandle** object.
**System capability**: SystemCapability.Communication.NetManager.Core
-### Parameters
+### Attributes
-| Name| Type | Description |
-| ------ | ------ | ------------------------- |
-| netId | number | Network ID. The value **0** indicates no default network. Any other value must be greater than or equal to 100.|
+| Name | Type | Mandatory| Description |
+| ------ | ------ | --- |------------------------- |
+| netId | number | Yes | Network ID. The value **0** indicates no default network. Any other value must be greater than or equal to 100.|
### bindSocket9+
-bindSocket(socketParam: TCPSocket \| UDPSocket, callback: AsyncCallback\): void;
+bindSocket(socketParam: TCPSocket \| UDPSocket, callback: AsyncCallback\): void
Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses an asynchronous callback to return the result.
-**Required permission**: ohos.permission.GET_NETWORK_INFO
-
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
@@ -886,24 +1499,33 @@ Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses
| Name | Type | Mandatory| Description |
| ----------- | ------------------------ | ---- | -------------------------------|
| socketParam | [TCPSocket](js-apis-socket.md#tcpsocket) \| [UDPSocket](js-apis-socket.md#udpsocket) | Yes| **TCPSocket** or **UDPSocket** object.|
-| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If the **TCPSocket** or **UDPSocket** object is successfully bound to the current network, **err** is **undefined**. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
import socket from "@ohos.net.socket";
-connection.getDefaultNet().then((netHandle)=>{
+connection.getDefaultNet().then((netHandle) => {
var tcp = socket.constructTCPSocketInstance();
var udp = socket.constructUDPSocketInstance();
let socketType = "TCPSocket";
if (socketType == "TCPSocket") {
tcp.bind({
- address: '192.168.xx.xxx', port: xxxx, family: 1
- }, err => {
- if (err) {
+ address: '192.168.xx.xxx', port: 8080, family: 1
+ }, error => {
+ if (error) {
console.log('bind fail');
}
- netHandle.bindSocket(tcp, (error, data)=>{
+ netHandle.bindSocket(tcp, (error, data) => {
if (error) {
console.log(JSON.stringify(error));
} else {
@@ -913,19 +1535,19 @@ connection.getDefaultNet().then((netHandle)=>{
})
} else {
let callback = value => {
- console.log(TAG + "on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo);
+ console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo);
}
udp.on('message', callback);
udp.bind({
- address: '192.168.xx.xxx', port: xxxx, family: 1
- }, err => {
- if (err) {
+ address: '192.168.xx.xxx', port: 8080, family: 1
+ }, error => {
+ if (error) {
console.log('bind fail');
}
udp.on('message', (data) => {
console.log(JSON.stringify(data))
});
- netHandle.bindSocket(udp,(error, data)=>{
+ netHandle.bindSocket(udp, (error, data) => {
if (error) {
console.log(JSON.stringify(error));
} else {
@@ -937,14 +1559,12 @@ connection.getDefaultNet().then((netHandle)=>{
})
```
-### bindSocket
+### bindSocket9+
bindSocket(socketParam: TCPSocket \| UDPSocket): Promise\;
Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses a promise to return the result.
-**Required permission**: ohos.permission.GET_NETWORK_INFO
-
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
@@ -959,56 +1579,60 @@ Binds a **TCPSocket** or **UDPSocket** object to the data network. This API uses
| -------------- | ---------------------- |
| Promise\ | Promise that returns no value.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
import socket from "@ohos.net.socket";
-connection.getDefaultNet().then((netHandle)=>{
+connection.getDefaultNet().then((netHandle) => {
var tcp = socket.constructTCPSocketInstance();
var udp = socket.constructUDPSocketInstance();
let socketType = "TCPSocket";
if (socketType == "TCPSocket") {
tcp.bind({
- address: '192.168.xx.xxx', port: xxxx, family: 1
- }, err => {
- if (err) {
+ address: '192.168.xx.xxx', port: 8080, family: 1
+ }, error => {
+ if (error) {
console.log('bind fail');
}
- netHandle.bindSocket(tcp).then((err, data) => {
- if (err) {
- console.log(JSON.stringify(err));
- } else {
- console.log(JSON.stringify(data));
- }
+ netHandle.bindSocket(tcp).then((data) => {
+ console.log(JSON.stringify(data));
+ }).catch(error => {
+ console.log(JSON.stringify(error));
})
})
} else {
let callback = value => {
- console.log(TAG + "on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo);
+ console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo);
}
udp.on('message', callback);
udp.bind({
- address: '192.168.xx.xxx', port: xxxx, family: 1
- }, err => {
- if (err) {
+ address: '192.168.xx.xxx', port: 8080, family: 1
+ }, error => {
+ if (error) {
console.log('bind fail');
}
udp.on('message', (data) => {
console.log(JSON.stringify(data));
})
- netHandle.bindSocket(udp).then((err, data) => {
- if (err) {
- console.log(JSON.stringify(err));
- } else {
- console.log(JSON.stringify(data));
- }
+ netHandle.bindSocket(udp).then((data) => {
+ console.log(JSON.stringify(data));
+ }).catch(error => {
+ console.log(JSON.stringify(error));
})
})
}
})
```
-
### getAddressesByName
getAddressesByName(host: string, callback: AsyncCallback\>): void
@@ -1023,17 +1647,27 @@ Resolves the host name by using the corresponding network to obtain all IP addre
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------ |
-| host | string | Yes | Host name to be resolved.|
-| callback | AsyncCallback\> | Yes | Callback used to return the result. |
+| host | string | Yes | Host name to resolve.|
+| callback | AsyncCallback\> | Yes | Callback used to return the result. If all IP addresses are successfully obtained, **err** is **undefined**, and **data** is the list of all obtained IP addresses. Otherwise, **err** is an error object.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
connection.getDefaultNet().then(function (netHandle) {
let host = "xxxx";
- netHandle.getAddressesByName(host, function (error, addresses) {
+ netHandle.getAddressesByName(host, function (error, data) {
console.log(JSON.stringify(error))
- console.log(JSON.stringify(addresses))
+ console.log(JSON.stringify(data))
})
})
```
@@ -1052,7 +1686,7 @@ Resolves the host name by using the corresponding network to obtain all IP addre
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
-| host | string | Yes | Host name to be resolved.|
+| host | string | Yes | Host name to resolve.|
**Return value**
@@ -1060,13 +1694,23 @@ Resolves the host name by using the corresponding network to obtain all IP addre
| ------------------------------------------- | ----------------------------- |
| Promise\> | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
connection.getDefaultNet().then(function (netHandle) {
let host = "xxxx";
- netHandle.getAddressesByName(host).then(function (addresses) {
- console.log(JSON.stringify(addresses))
+ netHandle.getAddressesByName(host).then(function (data) {
+ console.log(JSON.stringify(data))
})
})
```
@@ -1085,17 +1729,27 @@ Resolves the host name by using the corresponding network to obtain the first IP
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------ |
-| host | string | Yes | Host name to be resolved.|
-| callback | AsyncCallback\<[NetAddress](#netaddress)> | Yes | Callback used to return the result. |
+| host | string | Yes | Host name to resolve.|
+| callback | AsyncCallback\<[NetAddress](#netaddress)> | Yes | Callback used to return the result. If the first IP address is obtained successfully, **err** is **undefined**, and **data** is the first obtained IP address. Otherwise, **err** is an error object. |
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
**Example**
```js
connection.getDefaultNet().then(function (netHandle) {
let host = "xxxx";
- netHandle.getAddressByName(host, function (error, address) {
+ netHandle.getAddressByName(host, function (error, data) {
console.log(JSON.stringify(error))
- console.log(JSON.stringify(address))
+ console.log(JSON.stringify(data))
})
})
```
@@ -1114,7 +1768,7 @@ Resolves the host name by using the corresponding network to obtain the first IP
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------ |
-| host | string | Yes | Host name to be resolved.|
+| host | string | Yes | Host name to resolve.|
**Return value**
@@ -1122,66 +1776,88 @@ Resolves the host name by using the corresponding network to obtain the first IP
| ----------------------------------- | ------------------------------- |
| Promise\<[NetAddress](#netaddress)> | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
**Example**
```js
connection.getDefaultNet().then(function (netHandle) {
let host = "xxxx";
- netHandle.getAddressByName(host).then(function (address) {
- console.log(JSON.stringify(address))
+ netHandle.getAddressByName(host).then(function (data) {
+ console.log(JSON.stringify(data))
})
})
```
-## NetSpecifier
+## NetCap
-Provides an instance that bears data network capabilities.
+Defines the network capability.
**System capability**: SystemCapability.Communication.NetManager.Core
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| netCapabilities | [NetCapabilities](#netcapabilities) | Yes | Network transmission capabilities and bearer types of the data network. |
-| bearerPrivateIdentifier | string | No | Network identifier. The identifier of a Wi-Fi network is **wifi**, and that of a cellular network is **slot0** (corresponding to SIM card 1).|
+| Name | Value | Description |
+| ------------------------ | ---- | ---------------------- |
+| NET_CAPABILITY_MMS | 0 | The network can connect to the carrier's Multimedia Messaging Service Center (MMSC) to send and receive multimedia messages.|
+| NET_CAPABILITY_NOT_METERED | 11 | The network traffic is not metered.|
+| NET_CAPABILITY_INTERNET | 12 | The network has the Internet access capability, which is set by the network provider.|
+| NET_CAPABILITY_NOT_VPN | 15 | The network does not use a virtual private network (VPN).|
+| NET_CAPABILITY_VALIDATED | 16 | The Internet access capability of the network is successfully verified by the connection management module.|
-## NetCapabilities
+## NetBearType
-Defines the network capability set.
+Enumerates network types.
**System capability**: SystemCapability.Communication.NetManager.Core
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| linkUpBandwidthKbps | number | No | Uplink (from the device to the network) bandwidth.|
-| linkDownBandwidthKbps | number | No | Downlink (from the network to the device) bandwidth.|
-| networkCap | Array<[NetCap](#netcap)> | No | Network capability. |
-| bearerTypes | Array<[NetBearType](#netbeartype)> | Yes | Network type. |
+| Name | Value | Description |
+| --------------- | ---- | ----------- |
+| BEARER_CELLULAR | 0 | Cellular network. |
+| BEARER_WIFI | 1 | Wi-Fi network.|
+| BEARER_ETHERNET | 3 | Ethernet network.|
-## NetCap
+## HttpProxy10+
-Defines the network capability.
+Defines the global HTTP proxy configuration of the network.
**System capability**: SystemCapability.Communication.NetManager.Core
-| Name | Value | Description |
-| ------------------------ | ---- | ---------------------- |
-| NET_CAPABILITY_MMS | 0 | The network can connect to the carrier's Multimedia Messaging Service Center (MMSC) to send and receive multimedia messages.|
-| NET_CAPABILITY_NOT_METERED | 11 | The network traffic is not metered.|
-| NET_CAPABILITY_INTERNET | 12 | The network can connect to the Internet.|
-| NET_CAPABILITY_NOT_VPN | 15 | The network does not use a Virtual Private Network (VPN).|
-| NET_CAPABILITY_VALIDATED | 16 | The network is available. |
+| Name | Type | Mandatory| Description |
+| ------ | ------ | --- |------------------------- |
+| host | string | No | Host name of the proxy server.|
+| port | number | No | Host port.|
+| exclusionList | Array | No | List of hosts that do not use the proxy server.|
-## NetBearType
+## NetSpecifier
-Defines the network type.
+Provides an instance that bears data network capabilities.
**System capability**: SystemCapability.Communication.NetManager.Core
-| Name | Value | Description |
-| --------------- | ---- | ----------- |
-| BEARER_CELLULAR | 0 | Cellular network |
-| BEARER_WIFI | 1 | Wi-Fi network|
-| BEARER_ETHERNET | 3 | Ethernet network|
+| Name | Type | Mandatory | Description |
+| ----------------------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
+| netCapabilities | [NetCapabilities](#netcapabilities) | Yes | Network transmission capabilities and bearer types of the data network. |
+| bearerPrivateIdentifier | string | No | Network identifier. The identifier of a Wi-Fi network is **wifi**, and that of a cellular network is **slot0** (corresponding to SIM card 1).|
+
+## NetCapabilities
+
+Defines the network capability set.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+| Name | Type | Mandatory| Description |
+| --------------------- | ---------------------------------- | --- | ------------------------ |
+| linkUpBandwidthKbps | number | No| Uplink (from the device to the network) bandwidth. |
+| linkDownBandwidthKbps | number | No| Downlink (from the network to the device) bandwidth. |
+| networkCap | Array\<[NetCap](#netcap)> | No| Network capability. |
+| bearerTypes | Array\<[NetBearType](#netbeartype)> | Yes| Network type. |
## ConnectionProperties
@@ -1189,48 +1865,48 @@ Defines the network connection properties.
**System capability**: SystemCapability.Communication.NetManager.Core
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| interfaceName | string | Yes | NIC card name. |
-| domains | string | Yes | Domain. The default value is **""**.|
-| linkAddresses | Array\<[LinkAddress](#linkaddress)> | Yes | Link information. |
-| routes | Array\<[RouteInfo](#routeinfo)> | Yes | Route information. |
-| dnses | Array\<[NetAddress](#netaddress)>; | Yes | Network address. For details, see [NetAddress](#netaddress).|
-| mtu | number | Yes | Maximum transmission unit (MTU). |
+| Name | Type | Mandatory| Description |
+| ------------- | ---------------------------------- | ----|---------------- |
+| interfaceName | string | Yes|Network interface card (NIC) name. |
+| domains | string | Yes|Domain. The default value is **""**.|
+| linkAddresses | Array\<[LinkAddress](#linkaddress)> | Yes|Link information. |
+| routes | Array\<[RouteInfo](#routeinfo)> | Yes|Route information. |
+| dnses | Array\<[NetAddress](#netaddress)> | Yes|Network address. For details, see [NetAddress](#netaddress).|
+| mtu | number | Yes|Maximum transmission unit (MTU). |
-## LinkAddress
+## RouteInfo
-Network link information.
+Defines network route information.
**System capability**: SystemCapability.Communication.NetManager.Core
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| address | [NetAddress](#netaddress) | Yes | Link address. |
-| prefixLength | number | Yes | Length of the link address prefix.|
+| Name | Type | Mandatory|Description |
+| -------------- | --------------------------- | --- |---------------- |
+| interface | string | Yes|NIC name. |
+| destination | [LinkAddress](#linkaddress) | Yes|Destination address. |
+| gateway | [NetAddress](#netaddress) | Yes|Gateway address. |
+| hasGateway | boolean | Yes|Whether a gateway is present. |
+| isDefaultRoute | boolean | Yes|Whether the route is the default route.|
-## RouteInfo
+## LinkAddress
-Network route information.
+Defines network link information.
**System capability**: SystemCapability.Communication.NetManager.Core
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| interface | string | Yes | NIC card name. |
-| destination | [LinkAddress](#linkaddress) | Yes | Destination IP address. |
-| gateway | [NetAddress](#netaddress) | Yes | Gateway address. |
-| hasGateway | boolean | Yes | Whether a gateway is present. |
-| isDefaultRoute | boolean | Yes | Whether the route is the default route.|
+| Name | Type | Mandatory|Description |
+| ------------ | ----------------------- |---- |-------------------- |
+| address | [NetAddress](#netaddress) | Yes| Link address. |
+| prefixLength | number | Yes|Length of the link address prefix.|
## NetAddress
-Defines the network address.
+Defines a network address.
**System capability**: SystemCapability.Communication.NetManager.Core
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| address | string | Yes | Network address. |
-| family | number | Yes | Address family identifier. The value is **1** for IPv4 and **2** for IPv6. The default value is **1**.|
-| port | number | No | Port number. The value ranges from **0** to **65535**. |
+| Name | Type | Mandatory| Description |
+| ------- | ------ | -- |------------------------------ |
+| address | string | Yes|Network address. |
+| family | number | No|Address family identifier. The value is **1** for IPv4 and **2** for IPv6. The default value is **1**.|
+| port | number | No|Port number. The value ranges from **0** to **65535**. |
diff --git a/en/application-dev/reference/apis/js-apis-net-ethernet.md b/en/application-dev/reference/apis/js-apis-net-ethernet.md
index d41845ec1859507bb96a071dff2a57e16f4cf12b..3445952a9c818fad947373508accb50322e8cf59 100644
--- a/en/application-dev/reference/apis/js-apis-net-ethernet.md
+++ b/en/application-dev/reference/apis/js-apis-net-ethernet.md
@@ -1,8 +1,8 @@
-# @ohos.net.ethernet (Ethernet Connection Management)
+# # @ohos.net.ethernet (Ethernet Connection Management)
The **ethernet** module provides wired network capabilities, which allow users to set the IP address, subnet mask, gateway, and Domain Name System (DNS) server of a wired network.
-> **NOTE**
+> **NOTE**
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
@@ -17,30 +17,51 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallbac
Sets the network interface configuration. This API uses an asynchronous callback to return the result.
+**System API**: This is a system API.
+
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------------------ |
-| iface | string | Yes | Name of the network interface. |
+| iface | string | Yes | Interface name. |
| ic | [InterfaceConfiguration](#interfaceconfiguration) | Yes | Network interface configuration to set. |
| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------------------|
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service.|
+| 2200003 | System internal error. |
+| 2201005 | The device information does not exist. |
+| 2201006 | Device disconnected. |
+| 2201007 | Failed to write the user configuration. |
+
**Example**
```js
-ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", routeAddr:"192.168.1.1",
- gateAddr:"192.168.1.1", maskAddr:"255.255.255.0", dnsAddr0:"1.1.1.1", dnsAddr1:"2.2.2.2"},
- (error) => {
- if (error) {
- console.log("setIfaceConfig callback error = " + error);
- } else {
- console.log("setIfaceConfig callback ok ");
- }
- });
+ethernet.setIfaceConfig("eth0", {
+ mode: 0,
+ ipAddr: "192.168.xx.xxx",
+ route: "192.168.xx.xxx",
+ gateway: "192.168.xx.xxx",
+ netMask: "255.255.255.0",
+ dnsServers: "1.1.1.1",
+ domain: "2.2.2.2"
+}, (error) => {
+ if (error) {
+ console.log("setIfaceConfig callback error = " + JSON.stringify(error));
+ } else {
+ console.log("setIfaceConfig callback ok ");
+ }
+});
```
## ethernet.setIfaceConfig
@@ -49,31 +70,53 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\
Sets the network interface configuration. This API uses a promise to return the result.
+**System API**: This is a system API.
+
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------------------------- | ---- | ------------------------ |
-| iface | string | Yes | Name of the network interface. |
+| iface | string | Yes | Interface name. |
| ic | [InterfaceConfiguration](#interfaceconfiguration) | Yes | Network interface configuration to set.|
**Return value**
| Type | Description |
| ------------------- | ----------------------------------------------------------- |
-| Promise\ | Promise that returns no value.|
+| Promise\ | Promise used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------------------|
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service.|
+| 2200003 | System internal error. |
+| 2201005 | The device information does not exist. |
+| 2201006 | Device disconnected. |
+| 2201007 | Failed to write the user configuration. |
**Example**
```js
-ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", routeAddr:"192.168.1.1",
- gateAddr:"192.168.1.1", maskAddr:"255.255.255.0", dnsAddr0:"1.1.1.1", dnsAddr1:"2.2.2.2"}).then(() => {
+ethernet.setIfaceConfig("eth0", {
+ mode: 0,
+ ipAddr: "192.168.xx.xxx",
+ route: "192.168.xx.xxx",
+ gateway: "192.168.xx.xxx",
+ netMask: "255.255.255.0",
+ dnsServers: "1.1.1.1",
+ domain: "2.2.2.2"
+}).then(() => {
console.log("setIfaceConfig promiss ok ");
-}).catch((error) => {
- console.log("setIfaceConfig promiss error = " + error);
+}).catch(error => {
+ console.log("setIfaceConfig promiss error = " + JSON.stringify(error));
});
```
@@ -83,31 +126,44 @@ getIfaceConfig(iface: string, callback: AsyncCallback\):
Obtains the configuration of a network interface. This API uses an asynchronous callback to return the result.
+**System API**: This is a system API.
+
**Required permission**: ohos.permission.GET_NETWORK_INFO
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------------------- | ----- | ------------ |
-| iface | string | Yes | Name of the network interface.|
-| callback | AsyncCallback\<[InterfaceConfiguration](#interfaceconfiguration)> | Yes | Callback used to return the configuration. |
+| iface | string | Yes | Interface name.|
+| callback | AsyncCallback\<[InterfaceConfiguration](#interfaceconfiguration)> | Yes | Callback used to return the result. |
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------------------|
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service.|
+| 2200003 | System internal error. |
+| 2201005 | The device information does not exist. |
**Example**
```js
ethernet.getIfaceConfig("eth0", (error, value) => {
if (error) {
- console.log("getIfaceConfig callback error = " + error);
+ console.log("getIfaceConfig callback error = " + JSON.stringify(error));
} else {
- console.log("getIfaceConfig callback mode = " + value.mode);
- console.log("getIfaceConfig callback ipAddr = " + value.ipAddr);
- console.log("getIfaceConfig callback routeAddr = " + value.routeAddr);
- console.log("getIfaceConfig callback gateAddr = " + value.gateAddr);
- console.log("getIfaceConfig callback maskAddr = " + value.maskAddr);
- console.log("getIfaceConfig callback dns0Addr = " + value.dns0Addr);
- console.log("getIfaceConfig callback dns1Addr = " + value.dns1Addr);
+ console.log("getIfaceConfig callback mode = " + JSON.stringify(value.mode));
+ console.log("getIfaceConfig callback ipAddr = " + JSON.stringify(value.ipAddr));
+ console.log("getIfaceConfig callback route = " + JSON.stringify(value.route));
+ console.log("getIfaceConfig callback gateway = " + JSON.stringify(value.gateway));
+ console.log("getIfaceConfig callback netMask = " + JSON.stringify(value.netMask));
+ console.log("getIfaceConfig callback dnsServers = " + JSON.stringify(value.dnsServers));
+ console.log("getIfaceConfig callback domain = " + JSON.stringify(value.domain));
}
});
```
@@ -118,64 +174,90 @@ getIfaceConfig(iface: string): Promise\
Obtains the configuration of a network interface. This API uses a promise to return the result.
+**System API**: This is a system API.
+
**Required permission**: ohos.permission.GET_NETWORK_INFO
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------ |
-| iface | string | Yes | Name of the network interface.|
+| iface | string | Yes | Interface name.|
**Return value**
| Type | Description |
| --------------------------------- | ---------------------------------- |
-| Promise\<[InterfaceConfiguration](#interfaceconfiguration)> | Promise used to return the configuration. |
+| Promise\<[InterfaceConfiguration](#interfaceconfiguration)> | Promise used to return the result. |
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------------------|
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service.|
+| 2200003 | System internal error. |
+| 2201005 | The device information does not exist. |
**Example**
```js
ethernet.getIfaceConfig("eth0").then((data) => {
- console.log("getIfaceConfig promiss mode = " + data.mode);
- console.log("getIfaceConfig promiss ipAddr = " + data.ipAddr);
- console.log("getIfaceConfig promiss routeAddr = " + data.routeAddr);
- console.log("getIfaceConfig promiss gateAddr = " + data.gateAddr);
- console.log("getIfaceConfig promiss maskAddr = " + data.maskAddr);
- console.log("getIfaceConfig promiss dns0Addr = " + data.dns0Addr);
- console.log("getIfaceConfig promiss dns1Addr = " + data.dns1Addr);
-}).catch((error) => {
- console.log("getIfaceConfig promiss error = " + error);
+ console.log("getIfaceConfig promiss mode = " + JSON.stringify(data.mode));
+ console.log("getIfaceConfig promiss ipAddr = " + JSON.stringify(data.ipAddr));
+ console.log("getIfaceConfig promiss route = " + JSON.stringify(data.route));
+ console.log("getIfaceConfig promiss gateway = " + JSON.stringify(data.gateway));
+ console.log("getIfaceConfig promiss netMask = " + JSON.stringify(data.netMask));
+ console.log("getIfaceConfig promiss dnsServers = " + JSON.stringify(data.dnsServers));
+ console.log("getIfaceConfig promiss domain = " + JSON.stringify(data.domain));
+}).catch(error => {
+ console.log("getIfaceConfig promiss error = " + JSON.stringify(error));
});
```
## ethernet.isIfaceActive
-isIfaceActive(iface?: string, callback: AsyncCallback\): void
+isIfaceActive(iface: string, callback: AsyncCallback\): void
Checks whether a network interface is active. This API uses an asynchronous callback to return the result.
+**System API**: This is a system API.
+
**Required permission**: ohos.permission.GET_NETWORK_INFO
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------------------------------------- |
-| iface | string | Yes | Name of the network interface. If this parameter is left empty, the API checks for any active network interface. |
+| iface | string | Yes | Interface name. If this parameter is left empty, the API checks for any active network interface. |
| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **1** means that the network interface is active, **0** means that the network interface is inactive, and any other value means that an error has occurred.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------------------|
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service.|
+| 2200003 | System internal error. |
+| 2201005 | The device information does not exist. |
+
**Example**
```js
ethernet.isIfaceActive("eth0", (error, value) => {
- if (error) {
- console.log("whether2Activate callback error = " + error);
- } else {
- console.log("whether2Activate callback = " + value);
- }
+ if (error) {
+ console.log("whether2Activate callback error = " + JSON.stringify(error));
+ } else {
+ console.log("whether2Activate callback = " + JSON.stringify(value));
+ }
});
```
@@ -185,15 +267,17 @@ isIfaceActive(iface: string): Promise\
Checks whether a network interface is active. This API uses a promise to return the result.
+**System API**: This is a system API.
+
**Required permission**: ohos.permission.GET_NETWORK_INFO
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
-| iface | string | Yes | Name of the network interface. If this parameter is left empty, the API checks for any active network interface.|
+| iface | string | Yes | Interface name. If this parameter is left empty, the API checks for any active network interface.|
**Return value**
@@ -201,13 +285,24 @@ Checks whether a network interface is active. This API uses a promise to return
| ----------------| ------------------------------------------------------------------ |
| Promise\ | Promise used to return the result. The value **1** means that the network interface is active, **0** means that the network interface is inactive, and any other value means that an error has occurred.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------------------|
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service.|
+| 2200003 | System internal error. |
+| 2201005 | The device information does not exist. |
+
**Example**
```js
ethernet.isIfaceActive("eth0").then((data) => {
- console.log("isIfaceActive promiss = " + data);
-}).catch((error) => {
- console.log("isIfaceActive promiss error = " + error);
+ console.log("isIfaceActive promiss = " + JSON.stringify(data));
+}).catch(error => {
+ console.log("isIfaceActive promiss error = " + JSON.stringify(error));
});
```
@@ -215,30 +310,40 @@ ethernet.isIfaceActive("eth0").then((data) => {
getAllActiveIfaces(callback: AsyncCallback\>): void
-Obtains all active network interfaces. This API uses an asynchronous callback to return the result.
+Obtains the list of all active network interfaces. This API uses an asynchronous callback to return the result.
+
+**System API**: This is a system API.
**Required permission**: ohos.permission.GET_NETWORK_INFO
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------ |
-| callback | AsyncCallback\> | Yes | Callback used to return all the active network interface names obtained.|
+| callback | AsyncCallback\> | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------------------|
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service.|
+| 2200003 | System internal error. |
**Example**
```js
ethernet.getAllActiveIfaces((error, value) => {
- if (error) {
- console.log("getAllActiveIfaces callback error = " + error);
- } else {
- console.log("getAllActiveIfaces callback value.length = " + value.length);
- for (let i = 0; i < value.length; i++) {
- console.log("getAllActiveIfaces callback = " + value[i]);
+ if (error) {
+ console.log("getAllActiveIfaces callback error = " + JSON.stringify(error));
+ } else {
+ console.log("getAllActiveIfaces callback value.length = " + JSON.stringify(value.length));
+ for (let i = 0; i < value.length; i++) {
+ console.log("getAllActiveIfaces callback = " + JSON.stringify(value[i]));
+ }
}
- }
});
```
@@ -246,30 +351,38 @@ ethernet.getAllActiveIfaces((error, value) => {
getAllActiveIfaces(): Promise\>
-Obtains all active network interfaces. This API uses a promise to return the result.
+Obtains the list of all active network interfaces. This API uses a promise to return the result.
-**Required permission**: ohos.permission.GET_NETWORK_INFO
+**System API**: This is a system API.
-**System capability**: SystemCapability.Communication.NetManager.Core
+**Required permission**: ohos.permission.GET_NETWORK_INFO
-**Parameters**
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
**Return value**
| Type | Description |
| ------------------------------ | ----------------------------------------------- |
-| Promise\> | Promise used to return all the active network interface names obtained.|
+| Promise\> | Promise used to return the result. |
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------------------------|
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service.|
+| 2200003 | System internal error. |
**Example**
```js
ethernet.getAllActiveIfaces().then((data) => {
- console.log("getAllActiveIfaces promiss data.length = " + data.length);
- for (let i = 0; i < data.length; i++) {
- console.log("getAllActiveIfaces promiss = " + data[i]);
- }
-}).catch((error) => {
- console.log("getAllActiveIfaces promiss error = " + error);
+ console.log("getAllActiveIfaces promiss data.length = " + JSON.stringify(data.length));
+ for (let i = 0; i < data.length; i++) {
+ console.log("getAllActiveIfaces promiss = " + JSON.stringify(data[i]));
+ }
+}).catch(error => {
+ console.log("getAllActiveIfaces promiss error = " + JSON.stringify(error));
});
```
@@ -277,22 +390,26 @@ ethernet.getAllActiveIfaces().then((data) => {
Defines the network configuration for the Ethernet connection.
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System API**: This is a system API.
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| mode | [IPSetMode](#ipsetmode) | Yes | Configuration mode of the Ethernet connection.|
-| ipAddr | string | Yes | Static IP address of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in Dynamic Host Configuration Protocol (DHCP) mode.|
-| route | string | Yes | Route of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.|
-| gateway | string | Yes | Gateway of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.|
-| netMask | string | Yes | Subnet mask of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.|
-| dnsServers | string | Yes | DNS server addresses of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode. Multiple addresses are separated by commas (,).|
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
+
+| Name | Type | Mandatory| Description |
+| ------------ | ----------------------- | ---|------------------------------------------------------------ |
+| mode | [IPSetMode](#ipsetmode) | Yes| Configuration mode of the Ethernet connection.|
+| ipAddr | string | Yes| Static IP address of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in Dynamic Host Configuration Protocol (DHCP) mode.|
+| route | string | Yes| Route of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.|
+| gateway | string | Yes| Gateway of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.|
+| netMask | string | Yes| Subnet mask of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.|
+| dnsServers | string | Yes| DNS server addresses of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode. Multiple addresses are separated by commas (,).|
## IPSetMode
Defines the configuration mode of the Ethernet connection.
-**System capability**: SystemCapability.Communication.NetManager.Core
+**System API**: This is a system API.
+
+**System capability**: SystemCapability.Communication.NetManager.Ethernet
| Name | Value | Description |
| ------------------------ | ---- | ---------------------- |
diff --git a/en/application-dev/reference/apis/js-apis-net-policy.md b/en/application-dev/reference/apis/js-apis-net-policy.md
new file mode 100644
index 0000000000000000000000000000000000000000..375ee31e24b9a24d14aae0217f12b8cd78eb57b1
--- /dev/null
+++ b/en/application-dev/reference/apis/js-apis-net-policy.md
@@ -0,0 +1,1558 @@
+# @ohos.net.policy (Network Policy Management)
+
+The **policy** module provides APIs for managing network policies, through which you can control and manage the data volume used.
+
+> **NOTE**
+>
+> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
+
+## Modules to Import
+
+```js
+import policy from '@ohos.net.policy'
+```
+
+## policy.setBackgroundPolicy
+
+setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback\): void
+
+Sets a background network policy. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| isAllowed | boolean | Yes | Whether applications running in the background are allowed to use mobile data.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))), (error, data) => {
+ this.callBack(error, data);
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+});
+```
+
+## policy.setBackgroundPolicy
+
+setBackgroundPolicy(isAllowed: boolean): Promise\
+
+Sets a background network policy. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| isAllowed | boolean | Yes | Whether applications running in the background are allowed to use mobile data.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
+
+**Example**
+
+```js
+policy.setBackgroundPolicy(Boolean(Number.parseInt(this.isBoolean))).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+```
+
+## policy.isBackgroundAllowed
+
+isBackgroundAllowed(callback: AsyncCallback\): void
+
+Obtains the background network policy. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, **true** is returned, which means that applications running in the background are allowed to use mobile data. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.isBackgroundAllowed((error, data) => {
+ this.callBack(error, data);
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+});
+```
+
+## policy.isBackgroundAllowed
+
+isBackgroundAllowed(): Promise\;
+
+Obtains the background network policy. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result. If the operation is successful, **true** is returned, which means that applications running in the background are allowed to use mobile data. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.isBackgroundAllowed().then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.setPolicyByUid
+
+setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback\): void
+
+Sets an application-specific network policy. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes | Unique ID of the application.|
+| policy | [NetUidPolicy](#netuidpolicy) | Yes| Application-specific network policy to set.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
+}
+policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy), (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.setPolicyByUid
+
+setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\;
+
+Sets an application-specific network policy. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes | Unique ID of the application.|
+| policy | [NetUidPolicy](#netuidpolicy) | Yes| Application-specific network policy to set.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ uid: Number.parseInt(this.firstParam), policy: Number.parseInt(this.currentNetUidPolicy)
+}
+policy.setPolicyByUid(Number.parseInt(this.firstParam), Number.parseInt(this.currentNetUidPolicy)).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.getPolicyByUid
+
+getPolicyByUid(uid: number, callback: AsyncCallback\): void
+
+Obtains an application-specific network policy by **uid**. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| callback | AsyncCallback\<[NetUidPolicy](#netuidpolicy)> | Yes | Callback used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getPolicyByUid(Number.parseInt(this.firstParam), (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.getPolicyByUid
+
+getPolicyByUid(uid: number): Promise\;
+
+Obtains an application-specific network policy by **uid**. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\<[NetUidPolicy](#netuidpolicy)> | Promise used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getPolicyByUid(Number.parseInt(this.firstParam)).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.getUidsByPolicy
+
+getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback\>): void
+
+Obtains the UID array of applications configured with a certain application-specific network policy. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| policy | [NetUidPolicy](#netuidpolicy) | Yes| Target application-specific network policy.|
+| callback | AsyncCallback\> | Yes | Callback used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getUidsByPolicy(Number.parseInt(this.currentNetUidPolicy), (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.getUidsByPolicy
+
+function getUidsByPolicy(policy: NetUidPolicy): Promise\>;
+
+Obtains the UID array of applications configured with a certain application-specific network policy. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| policy | [NetUidPolicy](#netuidpolicy) | Yes| Target application-specific network policy.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\> | Promise used to return the result. If the operation is successful, the operation result is returned. If the operation fails, an error message is returned.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.getNetQuotaPolicies
+
+getNetQuotaPolicies(callback: AsyncCallback\>): void
+
+Obtains the network quota policies. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| callback | AsyncCallback\> | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getNetQuotaPolicies((error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.getNetQuotaPolicies
+
+getNetQuotaPolicies(): Promise\>;
+
+Obtains the network quota policies. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\> | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getNetQuotaPolicies().then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.setNetQuotaPolicies
+
+setNetQuotaPolicies(quotaPolicies: Array\, callback: AsyncCallback\): void
+
+Sets an array of network quota policies. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy)> | Yes| An array of network quota policies to set.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this.ident, periodDuration:this.periodDuration, warningBytes:Number.parseInt(this.warningBytes),
+ limitBytes:Number.parseInt(this.limitBytes), lastWarningRemind:this.lastWarningRemind, lastLimitRemind:this.lastLimitRemind, metered:Boolean(Number.parseInt(this.metered)), limitAction:this.limitAction};
+this.netQuotaPolicyList.push(param);
+
+policy.setNetQuotaPolicies(this.netQuotaPolicyList, (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.setNetQuotaPolicies
+
+setNetQuotaPolicies(quotaPolicies: Array\): Promise\;
+
+Sets an array of network quota policies. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| quotaPolicies | Array\<[NetQuotaPolicy](#netquotapolicy)> | Yes| An array of network quota policies to set.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result.|
+
+**Example**
+
+```js
+let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this.ident, periodDuration:this.periodDuration, warningBytes:Number.parseInt(this.warningBytes),
+ limitBytes:Number.parseInt(this.limitBytes), lastWarningRemind:this.lastWarningRemind, lastLimitRemind:this.lastLimitRemind, metered:Boolean(Number.parseInt(this.metered)), limitAction:this.limitAction};
+this.netQuotaPolicyList.push(param);
+
+policy.setNetQuotaPolicies(this.netQuotaPolicyList).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+```
+
+## policy.restoreAllPolicies
+
+restoreAllPolicies(iccid: string, callback: AsyncCallback\): void
+
+Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| iccid | string | Yes| SIM card ID.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+this.firstParam = iccid;
+policy.restoreAllPolicies(this.firstParam, (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.restoreAllPolicies
+
+restoreAllPolicies(iccid: string): Promise\;
+
+Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| iccid | string | Yes| SIM card ID.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+this.firstParam = iccid;
+policy.restoreAllPolicies(this.firstParam).then(function(error, data){
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.isUidNetAllowed
+
+isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback\): void
+
+Checks whether an application is allowed to access metered networks. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| isMetered | boolean | Yes| Whether the network is a metered network.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** means that the application is allowed to access metered networks, and **false** means the opposite.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+
+let param = {
+ uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
+}
+policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.isUidNetAllowed
+
+isUidNetAllowed(uid: number, isMetered: boolean): Promise\;
+
+Checks whether an application is allowed to access metered networks. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| isMetered | boolean | Yes| Whether the network is a metered network.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+
+let param = {
+ uid: Number.parseInt(this.firstParam), isMetered: Boolean(Number.parseInt(this.isBoolean))
+}
+policy.isUidNetAllowed(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.isUidNetAllowed
+
+isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback\): void
+
+Checks whether an application is allowed to access the given network. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| iface | string | Yes| Name of the target network.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** means that the application is allowed to access the given network, and **false** means the opposite.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+
+let param = {
+ uid: Number.parseInt(this.firstParam), iface: this.secondParam
+}
+policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam, (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.isUidNetAllowed
+
+isUidNetAllowed(uid: number, iface: string): Promise\;
+
+Checks whether an application is allowed to access the given network. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| iface | string | Yes| Name of the target network.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ uid: Number.parseInt(this.firstParam), iface: this.secondParam
+}
+policy.isUidNetAllowed(Number.parseInt(this.firstParam), this.secondParam).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.setDeviceIdleAllowList
+
+setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\): void
+
+Sets whether to add an application to the device idle allowlist. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
+| callback | callback: AsyncCallback\ | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
+}
+policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.setDeviceIdleAllowList
+
+setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\;
+
+Sets whether to add an application to the device idle allowlist. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
+}
+policy.setDeviceIdleAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.getDeviceIdleAllowList
+
+getDeviceIdleAllowList(callback: AsyncCallback\>): void
+
+Obtains the UID array of applications that are on the device idle allowlist. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| callback | AsyncCallback\> | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getDeviceIdleAllowList((error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.getDeviceIdleAllowList
+
+getDeviceIdleAllowList(): Promise\>;
+
+Obtains the UID array of applications that are on the device idle allowlist. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\> | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getDeviceIdleAllowList().then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+```
+
+## policy.getBackgroundPolicyByUid
+
+getBackgroundPolicyByUid(uid: number, callback: AsyncCallback\): void
+
+Obtains the background network policies configured for the given application. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| callback | AsyncCallback\<[NetBackgroundPolicy](#netbackgroundpolicy)> | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+this.firstParam = uid
+policy.getBackgroundPolicyByUid(Number.parseInt(this.firstParam), (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.getBackgroundPolicyByUid
+
+getBackgroundPolicyByUid(uid: number): Promise\;
+
+Obtains the background network policies configured for the given application. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\<[NetBackgroundPolicy](#netbackgroundpolicy)> | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+this.firstParam = uid
+policy.getBackgroundPolicyByUid(Number.parseInt(this.firstParam)).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+```
+
+## policy.resetPolicies
+
+resetPolicies(iccid: string, callback: AsyncCallback\): void
+
+Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| iccid | string | Yes| SIM card ID.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+this.firstParam = iccid
+policy.resetPolicies(this.firstParam, (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.resetPolicies
+
+resetPolicies(iccid: string): Promise\;
+
+Restores all the policies (cellular network, background network, firewall, and application-specific network policies) for the given SIM card. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| iccid | string | Yes| SIM card ID.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getUidsByPolicy(Number.parseInt(this.firstParam)).then(function(error, data) {
+
+})
+this.firstParam = iccid
+policy.resetPolicies(this.firstParam).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.updateRemindPolicy
+
+updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType, callback: AsyncCallback\): void
+
+Updates a reminder policy. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes| Network type.|
+| iccid | string | Yes| SIM card ID.|
+| remindType | [RemindType](#remindtype) | Yes| Reminder type.|
+| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
+}
+policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType), (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.updateRemindPolicy
+
+updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType): Promise\;
+
+Updates a reminder policy. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | Yes| Network type.|
+| iccid | string | Yes| SIM card ID.|
+| remindType | [RemindType](#remindtype) | Yes| Reminder type.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ netType: Number.parseInt(this.netType), iccid: this.firstParam, remindType: this.currentRemindType
+}
+policy.updateRemindPolicy(Number.parseInt(this.netType), this.firstParam, Number.parseInt(this.currentRemindType)).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.setPowerSaveAllowList
+
+setPowerSaveAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback\): void
+
+Sets whether to add an application to the power-saving allowlist. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
+| callback | callback: AsyncCallback\ | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
+}
+policy.setPowerSaveAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean)), (error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.setPowerSaveAllowList
+
+setPowerSaveAllowList(uid: number, isAllowed: boolean): Promise\;
+
+Sets whether to add an application to the power-saving allowlist. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| uid | number | Yes| Unique ID of the application.|
+| isAllowed | boolean | Yes| Whether to add the application to the allowlist.|
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\ | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2100001 | Invalid parameter value. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+let param = {
+ uid: Number.parseInt(this.firstParam), isAllowed: Boolean(Number.parseInt(this.isBoolean))
+}
+policy.setPowerSaveAllowList(Number.parseInt(this.firstParam), Boolean(Number.parseInt(this.isBoolean))).then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+
+```
+
+## policy.getPowerSaveAllowList
+
+getPowerSaveAllowList(callback: AsyncCallback\>): void
+
+Obtains the UID array of applications that are on the power-saving allowlist. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------- | ---- | ---------- |
+| callback | AsyncCallback\> | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getPowerSaveAllowList((error, data) => {
+ this.callBack(error, data);
+});
+```
+
+## policy.getPowerSaveAllowList
+
+getPowerSaveAllowList(): Promise\>;
+
+Obtains the UID array of applications that are on the device idle allowlist. This API uses a promise to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Return value**
+
+| Type | Description |
+| --------------------------------- | ------------------------------------- |
+| Promise\> | Promise used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2100002 | Operation failed. Cannot connect to service.|
+| 2100003 | System internal error. |
+
+**Example**
+
+```js
+policy.getPowerSaveAllowList().then(function(error, data) {
+ console.log(JSON.stringify(error))
+ console.log(JSON.stringify(data))
+})
+```
+
+## policy.on
+
+Functions as the handle to a network policy.
+
+### on('netUidPolicyChange')
+
+on(type: "netUidPolicyChange", callback: Callback\<{ uid: number, policy: NetUidPolicy }>): void
+
+Subscribes to policy changes. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
+| type | netUidPolicyChange | Yes| Event type. The value **netUidPolicyChange** indicates a policy change event.|
+| callback | Callback\<{ uid: number, policy: [NetUidPolicy](#netuidpolicy) }> | Yes | Callback used to return the result. It is called when the registered network policy changes.|
+
+**Example**
+
+```js
+policy.on('netUidPolicyChange', (data) => {
+ this.log('on netUidPolicyChange: ' + JSON.stringify(data));
+})
+```
+
+### on('netUidRuleChange')
+
+on(type: "netUidRuleChange", callback: Callback\<{ uid: number, rule: NetUidRule }>): void
+
+Subscribes to rule changes. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
+| type | netUidRuleChange | Yes| Event type. The value **netUidRuleChange** indicates a rule change event.|
+| callback | Callback\<{ uid: number, rule: [NetUidRule](#netuidrule) }> | Yes | Callback used to return the result. It is called when the registered rule changes.|
+
+**Example**
+
+```js
+policy.on('netUidRuleChange', (data) => {
+ this.log('on netUidRuleChange: ' + JSON.stringify(data));
+})
+```
+
+### on('netMeteredIfacesChange')
+
+on(type: "netMeteredIfacesChange", callback: Callback\>): void
+
+Subscribes to metered **iface** changes. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
+| type | netMeteredIfacesChange | Yes| Event type. The value **netMeteredIfacesChange** indicates a metered **iface** change event.|
+| callback | Callback\> | Yes | Callback used to return the result. It is called when the registered metered **iface** changes.|
+
+**Example**
+
+```js
+policy.on('netMeteredIfacesChange', (data) => {
+ this.log('on netMeteredIfacesChange: ' + JSON.stringify(data));
+})
+```
+
+### on('netQuotaPolicyChange')
+
+on(type: "netQuotaPolicyChange", callback: Callback\>): void
+
+Subscribes to network quota policy changes. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
+| type | netQuotaPolicyChange | Yes| Event type. The value **netQuotaPolicyChange** indicates a network quota policy change event.|
+| callback | Callback\> | Yes | Callback used to return the result. It is called when the registered network quota policy changes.|
+
+**Example**
+
+```js
+policy.on('netQuotaPolicyChange', (data) => {
+ this.log('on netQuotaPolicyChange: ' + JSON.stringify(data));
+})
+```
+
+### on('netBackgroundPolicyChange')
+
+on(type: "netBackgroundPolicyChange", callback: Callback\): void
+
+Subscribes to background network policy changes. This API uses an asynchronous callback to return the result.
+
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | ---------------------------------- | ---- | ------------------------------------------------------------ |
+| type | netBackgroundPolicyChange | Yes| Event type. The value **netBackgroundPolicyChange** indicates a background network policy change event.|
+| callback | Callback\ | Yes | Callback used to return the result. It is called when the registered background network policy changes.|
+
+**Example**
+
+```js
+policy.on('netBackgroundPolicyChange', (data) => {
+ this.log('on netBackgroundPolicyChange: ' + JSON.stringify(data));
+})
+```
+
+## NetBackgroundPolicy
+
+Enumerates the background network policies.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+| Name | Value | Description |
+| ------------------------ | ---- | ---------------------- |
+| NET_BACKGROUND_POLICY_NONE | 0 | Default policy.|
+| NET_BACKGROUND_POLICY_ENABLE | 1 | Applications running in the background are allowed to access metered networks.|
+| NET_BACKGROUND_POLICY_DISABLE | 2 | Applications running in the background are not allowed to access metered networks.|
+| NET_BACKGROUND_POLICY_ALLOW_LIST | 3 | Only applications on the allowlist are allowed to access metered networks when they are running in the background.|
+
+## NetQuotaPolicy
+
+Defines a network quota policy.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+| Name | Type | Description |
+| ----------------------- | ----------------------------------- | ------------------------------------------------------------ |
+| netType | [NetBearType](js-apis-net-connection.md#netbeartype) | Network type.|
+| iccid | string | Identifier of the SIM card on the metered cellular network. It is not used for Wi-Fi networks.|
+| ident | string | Identifier of the SIM card on the metered cellular network. It is used for Wi-Fi networks. It is used together with **iccid**.|
+| periodDuration | string | Start time of metering.|
+| warningBytes | number | Data volume threshold for generating an alarm.|
+| limitBytes | number | Data volume quota.|
+| lastWarningRemind | string | Last time when an alarm was generated.|
+| lastLimitRemind | string | Last time when the quota was exhausted.|
+| metered | string | Whether the network is a metered network.|
+| limitAction | [LimitAction](#limitaction) | Action to take when the data volume quota is reached.|
+
+## LimitAction
+
+Enumerates the actions that can be taken when the data volume quota is reached.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+| Name | Value| Description |
+| ---------------------- | ----- | ------------ |
+| LIMIT_ACTION_NONE | -1 | Default policy.|
+| LIMIT_ACTION_DISABLE | 0 | Internet access is disabled.|
+| LIMIT_ACTION_AUTO_BILL| 1 | Users will be automatically charged for the data volume they use.|
+
+## NetUidRule
+
+Enumerates the metered network rules.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+| Name | Value| Description |
+| ---------------------- | ----- | ------------ |
+| NET_RULE_NONE | 0 | Default rule.|
+| NET_RULE_ALLOW_METERED_FOREGROUND | 1 | Applications running in the foreground are allowed to access metered networks.|
+| NET_RULE_ALLOW_METERED | 2 | Applications are allowed to access metered networks.|
+| NET_RULE_REJECT_METERED | 4 | Applications are not allowed to access metered networks.|
+| NET_RULE_ALLOW_ALL | 32 | Applications are allowed to access all networks (metered or non-metered).|
+| NET_RULE_REJECT_ALL | 64 | Applications are not allowed to access any networks (metered or non-metered).|
+
+## RemindType
+
+Enumerates the reminder types.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+| Name | Value| Description |
+| ---------------------- | - | ------- |
+| REMIND_TYPE_WARNING | 1 | Warning.|
+| REMIND_TYPE_LIMIT | 2 | Limit.|
+
+## NetUidPolicy
+
+Enumerates the application-specific network policies.
+
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+| Name | Value| Description |
+| ---------------------- | ----- | ------------ |
+| NET_POLICY_NONE | 0 | Default network policy.|
+| NET_POLICY_ALLOW_METERED_BACKGROUND | 1 | Applications running in the background are allowed to access metered networks.|
+| NET_POLICY_REJECT_METERED_BACKGROUND | 2 | Applications running in the background are not allowed to access metered networks.|
diff --git a/en/application-dev/reference/apis/js-apis-net-sharing.md b/en/application-dev/reference/apis/js-apis-net-sharing.md
index 144ffa9c6e2d405c83e7cf14fdb7278c616759d3..f4682131182b59d9b54c26978ec780cd738172ef 100644
--- a/en/application-dev/reference/apis/js-apis-net-sharing.md
+++ b/en/application-dev/reference/apis/js-apis-net-sharing.md
@@ -1,8 +1,9 @@
-# @ohos.net.sharing (Network Sharing)
+# # @ohos.net.sharing (Network Sharing)
The **sharing** module allows you to share your device's Internet connection with other connected devices by means of Wi-Fi hotspot, Bluetooth, and USB sharing. It also allows you to query the network sharing state and shared mobile data volume.
-> **NOTE**
+> **NOTE**
+>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
@@ -29,6 +30,15 @@ Checks whether network sharing is supported. This API uses an asynchronous callb
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** means that network sharing is supported, and **false** means the opposite.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+| 2202011 | Cannot get network sharing configuration. |
+
**Example**
```js
@@ -56,6 +66,15 @@ Checks whether network sharing is supported. This API uses a promise to return t
| --------------------------------- | ------------------------------------- |
| Promise\ | Promise used to return the result. The value **true** means that network sharing is supported, and **false** means the opposite.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+| 2202011 | Cannot get network sharing configuration. |
+
**Example**
```js
@@ -84,6 +103,14 @@ Checks whether network sharing is in progress. This API uses an asynchronous cal
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result. The value **true** means that network sharing is in progress, and **false** means the opposite.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
@@ -99,10 +126,10 @@ isSharing(): Promise\
Checks whether network sharing is in progress. This API uses a promise to return the result.
-**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
-
**System API**: This is a system API.
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
**System capability**: SystemCapability.Communication.NetManager.NetSharing
**Return value**
@@ -111,6 +138,14 @@ Checks whether network sharing is in progress. This API uses a promise to return
| --------------------------------- | ------------------------------------- |
| Promise\ | Promise used to return the result. The value **true** means that network sharing is in progress, and **false** means the opposite.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
@@ -127,10 +162,10 @@ startSharing(type: SharingIfaceType, callback: AsyncCallback\): void
Starts network sharing of a specified type. This API uses an asynchronous callback to return the result.
-**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
-
**System API**: This is a system API.
+**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
+
**System capability**: SystemCapability.Communication.NetManager.NetSharing
**Parameters**
@@ -140,11 +175,27 @@ Starts network sharing of a specified type. This API uses an asynchronous callba
| type | [SharingIfaceType](#sharingifacetype) | Yes | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+| 2202004 | Try to share an unavailable iface. |
+| 2202005 | WiFi sharing failed. |
+| 2202006 | Bluetooth sharing failed. |
+| 2202009 | Network share enable forwarding error. |
+| 2202011 | Cannot get network sharing configuration. |
+
**Example**
```js
import SharingIfaceType from '@ohos.net.sharing'
-sharing.startSharing(SharingIfaceType.SHARING_WIFI, (error) => {
+let SHARING_WIFI=0;
+sharing.startSharing(SHARING_WIFI, (error) => {
console.log(JSON.stringify(error));
});
```
@@ -173,11 +224,27 @@ Starts network sharing of a specified type. This API uses a promise to return th
| --------------------------------- | ------------------------------------- |
| Promise\ | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+| 2202004 | Try to share an unavailable iface. |
+| 2202005 | WiFi sharing failed. |
+| 2202006 | Bluetooth sharing failed. |
+| 2202009 | Network share enable forwarding error. |
+| 2202011 | Cannot get network sharing configuration. |
+
**Example**
```js
import SharingIfaceType from '@ohos.net.sharing'
-sharing.startSharing(SharingIfaceType.SHARING_WIFI).then(() => {
+let SHARING_WIFI=0;
+sharing.startSharing(SHARING_WIFI).then(() => {
console.log("start wifi sharing successful");
}).catch(error => {
console.log("start wifi sharing failed");
@@ -203,11 +270,25 @@ Stops network sharing of a specified type. This API uses an asynchronous callbac
| type | [SharingIfaceType](#sharingifacetype) | Yes | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+| 2202005 | WiFi sharing failed. |
+| 2202006 | Bluetooth sharing failed. |
+| 2202011 | Cannot get network sharing configuration. |
+
**Example**
```js
import SharingIfaceType from '@ohos.net.sharing'
-sharing.stopSharing(SharingIfaceType.SHARING_WIFI, (error) => {
+let SHARING_WIFI=0;
+sharing.stopSharing(SHARING_WIFI, (error) => {
console.log(JSON.stringify(error));
});
```
@@ -236,11 +317,25 @@ Stops network sharing of a specified type. This API uses a promise to return the
| --------------------------------- | ------------------------------------- |
| Promise\ | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+| 2202005 | WiFi sharing failed. |
+| 2202006 | Bluetooth sharing failed. |
+| 2202011 | Cannot get network sharing configuration. |
+
**Example**
```js
import SharingIfaceType from '@ohos.net.sharing'
-sharing.stopSharing(SharingIfaceType.SHARING_WIFI).then(() => {
+let SHARING_WIFI=0;
+sharing.stopSharing(SHARING_WIFI).then(() => {
console.log("stop wifi sharing successful");
}).catch(error => {
console.log("stop wifi sharing failed");
@@ -265,6 +360,14 @@ Obtains the volume of mobile data traffic received via network sharing. This API
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\ | Yes | Callback used to return the data volume, in KB.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
@@ -292,6 +395,14 @@ Obtains the volume of mobile data traffic received via network sharing. This API
| --------------------------------- | ------------------------------------- |
| Promise\ | Promise used to return the data volume, in KB.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
@@ -320,6 +431,14 @@ Obtains the volume of mobile data traffic sent via network sharing. This API use
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\ | Yes | Callback used to return the data volume, in KB.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
@@ -347,6 +466,14 @@ Obtains the volume of mobile data traffic sent via network sharing. This API use
| --------------------------------- | ------------------------------------- |
| Promise\ | Promise used to return the data volume, in KB.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
@@ -375,6 +502,14 @@ Obtains the volume of mobile data traffic sent and received via network sharing.
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\ | Yes | Callback used to return the data volume, in KB.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
@@ -402,6 +537,14 @@ Obtains the volume of mobile data traffic sent and received via network sharing.
| --------------------------------- | ------------------------------------- |
| Promise\ | Promise used to return the data volume, in KB.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
@@ -428,14 +571,25 @@ Obtains the names of NICs in the specified network sharing state. This API uses
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
-| state | [SharingIfaceState](#sharingifacestate) | Yes | Network sharing state.|
+| state | [SharingIfaceState](#sharingifacestate) | Yes | Network sharing state.|
| callback | AsyncCallback\> | Yes | Callback used to return an array of NIC names.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
-import SharingIfaceType from '@ohos.net.sharing'
-sharing.getSharingIfaces(SharingIfaceState.SHARING_NIC_CAN_SERVER, (error, data) => {
+import SharingIfaceState from '@ohos.net.sharing'
+let SHARING_BLUETOOTH=2;
+sharing.getSharingIfaces(SHARING_BLUETOOTH, (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
@@ -457,7 +611,7 @@ Obtains the names of NICs in the specified network sharing state. This API uses
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
-| state | [SharingIfaceState](#sharingifacestate) | Yes | Network sharing state.|
+| state | [SharingIfaceState](#sharingifacestate) | Yes | Network sharing state.|
**Return value**
@@ -465,11 +619,22 @@ Obtains the names of NICs in the specified network sharing state. This API uses
| --------------------------------- | ------------------------------------- |
| Promise\> | Promise used to return an array of NIC names.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
import SharingIfaceState from '@ohos.net.sharing'
-sharing.getSharingIfaces(SharingIfaceState.SHARING_NIC_CAN_SERVER).then(data => {
+let SHARING_BLUETOOTH=2;
+sharing.getSharingIfaces(SHARING_BLUETOOTH).then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
@@ -495,11 +660,22 @@ Obtains the network sharing state of the specified type. This API uses an asynch
| type | [SharingIfaceType](#sharingifacetype) | Yes | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
| callback | AsyncCallback\<[SharingIfaceState](#sharingifacestate)> | Yes | Callback used to return the network sharing state.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
-import SharingIfaceState from '@ohos.net.sharing'
-sharing.getSharingState(SharingIfaceType.SHARING_WIFI, (error, data) => {
+import SharingIfaceType from '@ohos.net.sharing'
+let SHARING_WIFI=0;
+sharing.getSharingState(SHARING_WIFI, (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
@@ -523,6 +699,16 @@ Obtains the network sharing state of the specified type. This API uses a promise
| -------- | --------------------------------------- | ---- | ---------- |
| type | [SharingIfaceType](#sharingifacetype) | Yes | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Return value**
| Type | Description |
@@ -533,7 +719,8 @@ Obtains the network sharing state of the specified type. This API uses a promise
```js
import SharingIfaceType from '@ohos.net.sharing'
-sharing.getSharingState(SharingIfaceType.SHARING_WIFI).then(data => {
+let SHARING_WIFI=0;
+sharing.getSharingState(SHARING_WIFI).then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
@@ -559,11 +746,22 @@ Obtains regular expressions of NICs of a specified type. This API uses an asynch
| type | [SharingIfaceType](#sharingifacetype) | Yes | Sharing type. The value **0** means Wi-Fi hotspot sharing, **1** means USB sharing, and **2** means Bluetooth sharing.|
| callback | AsyncCallback\> | Yes | Callback used to return an array of regular expressions.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
import SharingIfaceType from '@ohos.net.sharing'
-sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI, (error, data) => {
+let SHARING_WIFI=0;
+sharing.getSharableRegexes(SHARING_WIFI, (error, data) => {
console.log(JSON.stringify(error));
console.log(JSON.stringify(data));
});
@@ -593,11 +791,22 @@ Obtains regular expressions of NICs of a specified type. This API uses a promise
| --------------------------------- | ------------------------------------- |
| Promise\> | Promise used to return an array of regular expressions.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 2200001 | Invalid parameter value. |
+| 2200002 | Operation failed. Cannot connect to service. |
+| 2200003 | System internal error. |
+
**Example**
```js
import SharingIfaceType from '@ohos.net.sharing'
-sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI).then(data => {
+let SHARING_WIFI=0;
+sharing.getSharableRegexes(SHARING_WIFI).then(data => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
@@ -621,14 +830,20 @@ Subscribes to network sharing state changes. This API uses an asynchronous callb
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | Yes | Event name.|
-| callback | AsyncCallback\ | Yes | Callback used to return the network sharing state.|
+| callback | AsyncCallback\ | Yes | Callback invoked when the network sharing state changes.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
**Example**
```js
-sharing.on('sharingStateChange', (error, data) => {
- console.log(JSON.stringify(error));
- console.log(JSON.stringify(data));
+ sharing.on('sharingStateChange', (data) => {
+ console.log('on sharingStateChange: ' + JSON.stringify(data));
});
```
@@ -649,13 +864,19 @@ Unsubscribes from network sharing state changes. This API uses an asynchronous c
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | Yes | Event name.|
-| callback | AsyncCallback\ | No | Callback used for unsubscription.|
+| callback | AsyncCallback\ | No | Callback invoked when the network sharing state changes.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
**Example**
```js
-sharing.off('sharingStateChange', (error, data) => {
- console.log(JSON.stringify(error));
+sharing.off('sharingStateChange', (data) => {
console.log(JSON.stringify(data));
});
```
@@ -679,12 +900,18 @@ Subscribes to network sharing state changes of a specified NIC. This API uses an
| type | string | Yes | Event name.|
| callback | AsyncCallback\<{ type: [SharingIfaceType](#sharingifacetype), iface: string, state: SharingIfaceState(#sharingifacestate) }> | Yes | Callback invoked when the network sharing state of the specified NIC changes.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+
**Example**
```js
-sharing.on('interfaceSharingStateChange', (error, data) => {
- console.log(JSON.stringify(error));
- console.log(JSON.stringify(data));
+ sharing.on('interfaceSharingStateChange', (data) => {
+ console.log('on interfaceSharingStateChange: ' + JSON.stringify(data));
});
```
@@ -705,13 +932,19 @@ Unsubscribes from network sharing status changes of a specified NIC. This API us
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | Yes | Event name.|
-| callback | AsyncCallback\<{ type: [SharingIfaceType](#sharingifacetype), iface: string, state: SharingIfaceState(#sharingifacestate) }> | No | Callback used for unsubscription.|
+| callback | AsyncCallback\<{ type: [SharingIfaceType](#sharingifacetype), iface: string, state: SharingIfaceState(#sharingifacestate) }> | No | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
**Example**
```js
-sharing.off('interfaceSharingStateChange', (error, data) => {
- console.log(JSON.stringify(error));
+sharing.off('interfaceSharingStateChange', (data) => {
console.log(JSON.stringify(data));
});
```
@@ -735,12 +968,18 @@ Subscribes to upstream network changes. This API uses an asynchronous callback t
| type | string | Yes | Event name.|
| callback | AsyncCallback\ | Yes | Callback invoked when the upstream network changes.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+
**Example**
```js
-sharing.on('sharingUpstreamChange', (error, data) => {
- console.log(JSON.stringify(error));
- console.log(JSON.stringify(data));
+ sharing.on('sharingUpstreamChange', (data) => {
+ console.log('on sharingUpstreamChange: ' + JSON.stringify(data));
});
```
@@ -761,13 +1000,19 @@ Unsubscribes from upstream network changes. This API uses an asynchronous callba
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | Yes | Event name.|
-| callback | AsyncCallback\ | No | Callback used for unsubscription.|
+| callback | AsyncCallback\ | No | Callback used for unsubscription from upstream network changes.|
+
+**Error codes**
+
+| ID| Error Message |
+| ------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
**Example**
```js
-sharing.off('sharingUpstreamChange', (error, data) => {
- console.log(JSON.stringify(error));
+sharing.off('sharingUpstreamChange', (data) => {
console.log(JSON.stringify(data));
});
```
@@ -788,7 +1033,7 @@ Enumerates the network sharing states of an NIC.
## SharingIfaceType
-Enumerates the network sharing types of an NIC.
+Enumerates the network sharing types of an NIC.
**System API**: This is a system API.
@@ -797,5 +1042,5 @@ Enumerates the network sharing types of an NIC.
| Name | Value | Description |
| ------------------------ | ---- | ---------------------- |
| SHARING_WIFI | 0 | Wi-Fi hotspot sharing.|
-| SHARING_USB | 1 | USB sharing (not supported currently).|
+| SHARING_USB | 1 | USB sharing.|
| SHARING_BLUETOOTH | 2 | Bluetooth sharing.|
diff --git a/en/application-dev/reference/apis/js-apis-pointer.md b/en/application-dev/reference/apis/js-apis-pointer.md
index 3a31a8179560f622bcf62e7d3c3640a72436beb5..49ed81e115de6345453c93441b68cda2a132021b 100644
--- a/en/application-dev/reference/apis/js-apis-pointer.md
+++ b/en/application-dev/reference/apis/js-apis-pointer.md
@@ -2,7 +2,8 @@
The **pointer** module provides APIs related to pointer attribute management.
-> **NOTE**
+> **NOTE**
+>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
@@ -237,6 +238,8 @@ Obtains the mouse movement speed. This API uses a promise to return the result.
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
+**System API**: This is a system API.
+
**Return value**
| Name | Description |
@@ -263,8 +266,6 @@ Obtains the mouse pointer style. This API uses an asynchronous callback to retur
**System capability**: SystemCapability.MultimodalInput.Input.Pointer
-**System API**: This is a system API.
-
**Parameters**
| Name | Type | Mandatory | Description |
@@ -277,21 +278,23 @@ Obtains the mouse pointer style. This API uses an asynchronous callback to retur
```js
import window from '@ohos.window';
-window.getTopWindow((error, win) => {
- win.getProperties((error, properties) => {
- let windowId = properties.id;
- if (windowId < 0) {
- console.log(`Invalid windowId`);
- return;
- }
- try {
- pointer.getPointerStyle(windowId, (error, style) => {
- console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
- });
- } catch (error) {
- console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- });
+window.getLastWindow(this.context, (error, win) => {
+ if (error.code) {
+ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
+ return;
+ }
+ let windowId = win.getWindowProperties().id;
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ pointer.getPointerStyle(windowId, (error, style) => {
+ console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
+ });
+ } catch (error) {
+ console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
+ }
});
```
@@ -320,21 +323,23 @@ Obtains the mouse pointer style. This API uses a promise to return the result.
```js
import window from '@ohos.window';
-window.getTopWindow((error, win) => {
- win.getProperties((error, properties) => {
- let windowId = properties.id;
- if (windowId < 0) {
- console.log(`Invalid windowId`);
- return;
- }
- try {
- pointer.getPointerStyle(windowId).then((style) => {
- console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
- });
- } catch (error) {
- console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- });
+window.getLastWindow(this.context, (error, win) => {
+ if (error.code) {
+ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
+ return;
+ }
+ let windowId = win.getWindowProperties().id;
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ pointer.getPointerStyle(windowId).then((style) => {
+ console.log(`Get pointer style success, style: ${JSON.stringify(style)}`);
+ });
+ } catch (error) {
+ console.log(`Get pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
+ }
});
```
@@ -359,21 +364,23 @@ Sets the mouse pointer style. This API uses an asynchronous callback to return t
```js
import window from '@ohos.window';
-window.getTopWindow((error, win) => {
- win.getProperties((error, properties) => {
- let windowId = properties.id;
- if (windowId < 0) {
- console.log(`Invalid windowId`);
- return;
- }
- try {
- pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => {
- console.log(`Set pointer style success`);
- });
- } catch (error) {
- console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- });
+window.getLastWindow(this.context, (error, win) => {
+ if (error.code) {
+ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
+ return;
+ }
+ let windowId = win.getWindowProperties().id;
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS, error => {
+ console.log(`Set pointer style success`);
+ });
+ } catch (error) {
+ console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
+ }
});
```
## pointer.setPointerStyle9+
@@ -397,21 +404,23 @@ Sets the mouse pointer style. This API uses a promise to return the result.
```js
import window from '@ohos.window';
-window.getTopWindow((error, win) => {
- win.getProperties((error, properties) => {
- let windowId = properties.id;
- if (windowId < 0) {
- console.log(`Invalid windowId`);
- return;
- }
- try {
- pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
- console.log(`Set pointer style success`);
- });
- } catch (error) {
- console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
- }
- });
+window.getLastWindow(this.context, (error, win) => {
+ if (error.code) {
+ console.error('Failed to obtain the top window. Cause: ' + JSON.stringify(error));
+ return;
+ }
+ let windowId = win.getWindowProperties().id;
+ if (windowId < 0) {
+ console.log(`Invalid windowId`);
+ return;
+ }
+ try {
+ pointer.setPointerStyle(windowId, pointer.PointerStyle.CROSS).then(() => {
+ console.log(`Set pointer style success`);
+ });
+ } catch (error) {
+ console.log(`Set pointer style failed, error: ${JSON.stringify(error, [`code`, `message`])}`);
+ }
});
```
## PointerStyle9+
@@ -444,8 +453,8 @@ Enumerates mouse pointer styles.
| HAND_POINTING | 19 | Hand-shaped pointer |![Hand_Poniting.png](./figures/Hand_Pointing.png)|
| HELP | 20 | Help |![Help.png](./figures/Help.png)|
| MOVE | 21 | Move |![Move.png](./figures/Move.png)|
-| RESIZE_LEFT_RIGHT | 22 | Left-and-right resizing|![Resize_Left_Right.png](./figures/Resize_Left_Right.png)|
-| RESIZE_UP_DOWN | 23 | Up-and-down resizing|![Resize_Up_Down.png](./figures/Resize_Up_Down.png)|
+| RESIZE_LEFT_RIGHT | 22 | Left and right resizing|![Resize_Left_Right.png](./figures/Resize_Left_Right.png)|
+| RESIZE_UP_DOWN | 23 | Up and down resizing|![Resize_Up_Down.png](./figures/Resize_Up_Down.png)|
| SCREENSHOT_CHOOSE | 24 | Screenshot crosshair|![Screenshot_Cross.png](./figures/Screenshot_Cross.png)|
| SCREENSHOT_CURSOR | 25 | Screenshot cursor |![Screenshot_Cursor.png](./figures/Screenshot_Cursor.png)|
| TEXT_CURSOR | 26 | Text cursor |![Text_Cursor.png](./figures/Text_Cursor.png)|
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 54cf7cc816d7def45a86a450765c5b23b9ef2a06..9f259f378ac523284d4aa17bce9742ec9b812636 100644
--- a/en/application-dev/reference/apis/js-apis-resource-manager.md
+++ b/en/application-dev/reference/apis/js-apis-resource-manager.md
@@ -19,8 +19,9 @@ Since API version 9, the stage model allows an application to obtain a **Resourc
For details about how to reference context in the stage model, see [Context in the Stage Model](../..//application-models/application-context-stage.md).
```ts
-import Ability from '@ohos.application.Ability';
-class MainAbility extends Ability {
+import UIAbility from '@ohos.app.ability.UIAbility';
+
+export default class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage) {
let context = this.context;
let resourceManager = context.resourceManager;
diff --git a/en/application-dev/reference/apis/js-apis-socket.md b/en/application-dev/reference/apis/js-apis-socket.md
index bd14137464ce195f5c61b9d6a53ce6ef79cd3f10..f099ece8f25d5fcb6ba4f5c753d55fa2a4f83717 100644
--- a/en/application-dev/reference/apis/js-apis-socket.md
+++ b/en/application-dev/reference/apis/js-apis-socket.md
@@ -1,8 +1,7 @@
-# @ohos.net.socket (Socket Connection)
+# # @ohos.net.socket (Socket Connection)
-The **socket** module implements socket connection management and operation.
-
-> **NOTE**
+> **NOTE**
+>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
@@ -13,7 +12,7 @@ import socket from '@ohos.net.socket';
## socket.constructUDPSocketInstance
-constructUDPSocketInstance\(\): UDPSocket
+constructUDPSocketInstance(): UDPSocket
Creates a **UDPSocket** object.
@@ -22,7 +21,7 @@ Creates a **UDPSocket** object.
**Return value**
| Type | Description |
-| --------------------------------- | ---------------------- |
+| :--------------------------------- | :---------------------- |
| [UDPSocket](#udpsocket) | **UDPSocket** object.|
@@ -39,7 +38,7 @@ Defines a **UDPSocket** connection. Before invoking UDPSocket APIs, you need to
### bind
-bind\(address: NetAddress, callback: AsyncCallback\): void
+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.
@@ -54,6 +53,13 @@ Binds the IP address and port number. The port number can be specified or random
| address | [NetAddress](#netaddress) | Yes | Destination address. For details, see [NetAddress](#netaddress).|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -70,7 +76,7 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
### bind
-bind\(address: NetAddress\): Promise
+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.
@@ -84,11 +90,17 @@ Binds the IP address and port number. The port number can be specified or random
| ------- | ---------------------------------- | ---- | ------------------------------------------------------ |
| address | [NetAddress](#netaddress) | Yes | Destination address. For details, see [NetAddress](#netaddress).|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
**Return value**
| Type | Description |
-| -------------- | ----------------------------------------- |
+| :-------------- | :----------------------------------------- |
| Promise\ | Promise used to return the result.|
**Example**
@@ -106,7 +118,7 @@ promise .then(() => {
### send
-send\(options: UDPSendOptions, callback: AsyncCallback\): void
+send(options: UDPSendOptions, callback: AsyncCallback\): void
Sends data over a UDPSocket connection. This API uses an asynchronous callback to return the result.
@@ -123,6 +135,13 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p
| options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDPSocket connection. For details, see [UDPSendOptions](#udpsendoptions).|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -146,7 +165,7 @@ udp.send({
### send
-send\(options: UDPSendOptions\): Promise
+send(options: UDPSendOptions): Promise\
Sends data over a UDPSocket connection. This API uses a promise to return the result.
@@ -162,10 +181,17 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p
| ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDPSocket connection. For details, see [UDPSendOptions](#udpsendoptions).|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Return value**
| Type | Description |
-| -------------- | --------------------------------------------- |
+| :-------------- | :--------------------------------------------- |
| Promise\ | Promise used to return the result.|
**Example**
@@ -190,7 +216,7 @@ promise.then(() => {
### close
-close\(callback: AsyncCallback\): void
+close(callback: AsyncCallback\): void
Closes a UDPSocket connection. This API uses an asynchronous callback to return the result.
@@ -220,7 +246,7 @@ udp.close(err => {
### close
-close\(\): Promise
+close(): Promise\
Closes a UDPSocket connection. This API uses a promise to return the result.
@@ -231,7 +257,7 @@ Closes a UDPSocket connection. This API uses a promise to return the result.
**Return value**
| Type | Description |
-| -------------- | ----------------------------------------- |
+| :-------------- | :----------------------------------------- |
| Promise\ | Promise used to return the result.|
**Example**
@@ -249,12 +275,12 @@ promise.then(() => {
### getState
-getState\(callback: AsyncCallback\): void
+getState(callback: AsyncCallback\): void
Obtains the status of the UDPSocket connection. This API uses an asynchronous callback to return the result.
->**NOTE**
->This API can be called only after [bind](#bind) is successfully called.
+>**NOTE**
+>This API can be called only after **bind** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -266,6 +292,12 @@ Obtains the status of the UDPSocket connection. This API uses an asynchronous ca
| -------- | ------------------------------------------------------ | ---- | ---------- |
| callback | AsyncCallback<[SocketStateBase](#socketstatebase)> | Yes | Callback used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -289,12 +321,12 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
### getState
-getState\(\): Promise
+getState(): Promise\
Obtains the status of the UDPSocket connection. This API uses a promise to return the result.
->**NOTE**
->This API can be called only after [bind](#bind) is successfully called.
+>**NOTE**
+>This API can be called only after **bind** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -303,8 +335,8 @@ Obtains the status of the UDPSocket connection. This API uses a promise to retur
**Return value**
| Type | Description |
-| ----------------------------------------------- | ----------------------------------------- |
-| Promise<[SocketStateBase](#socketstatebase)> | Promise used to return the result.|
+| :----------------------------------------------- | :----------------------------------------- |
+| Promise\<[SocketStateBase](#socketstatebase)\> | Promise used to return the result.|
**Example**
@@ -328,12 +360,12 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
### setExtraOptions
-setExtraOptions\(options: UDPExtraOptions, callback: AsyncCallback\): void
+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 attributes of the UDPSocket connection. This API uses an asynchronous callback to return the result.
->**NOTE**
->This API can be called only after [bind](#bind) is successfully called.
+>**NOTE**
+>This API can be called only after **bind** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -346,6 +378,12 @@ Sets other properties of the UDPSocket connection. This API uses an asynchronous
| options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDPSocket connection. For details, see [UDPExtraOptions](#udpextraoptions).|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
**Example**
@@ -376,12 +414,12 @@ udp.bind({address:'192.168.xx.xxx', port:xxxx, family:1}, err=> {
### setExtraOptions
-setExtraOptions\(options: UDPExtraOptions\): Promise
+setExtraOptions(options: UDPExtraOptions): Promise\
-Sets other properties of the UDPSocket connection. This API uses a promise to return the result.
+Sets other attributes of the UDPSocket connection. This API uses a promise to return the result.
->**NOTE**
->This API can be called only after [bind](#bind) is successfully called.
+>**NOTE**
+>This API can be called only after **bind** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -396,9 +434,16 @@ Sets other properties of the UDPSocket connection. This API uses a promise to re
**Return value**
| Type | Description |
-| -------------- | --------------------------------------------------- |
+| :-------------- | :--------------------------------------------------- |
| Promise\ | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -424,9 +469,9 @@ promise.then(() => {
```
-### on\('message'\)
+### on('message')
-on\(type: 'message', callback: Callback<\{message: ArrayBuffer, remoteInfo: SocketRemoteInfo\}\>\): void
+on(type: 'message', callback: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for message receiving events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
@@ -437,7 +482,7 @@ Enables listening for message receiving events of the UDPSocket connection. This
| 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)}> | Yes | Callback used to return the result. |
+| callback | Callback\<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}\> | Yes | Callback used to return the result. |
**Example**
@@ -449,13 +494,13 @@ udp.on('message', value => {
```
-### off\('message'\)
+### off('message')
-off\(type: 'message', callback?: Callback<\{message: ArrayBuffer, remoteInfo: SocketRemoteInfo\}\>\): void
+off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for message receiving events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
->**NOTE**
+>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
@@ -475,15 +520,15 @@ let callback = value =>{
console.log("on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo);
}
udp.on('message', callback);
-// You can pass the **callback** of the **on** method to cancel listening for a certain type of callback. If you do not pass the **callback**, you will cancel listening for all callbacks.
+// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks.
udp.off('message', callback);
udp.off('message');
```
-### on\('listening' | 'close'\)
+### on('listening' | 'close')
-on\(type: 'listening' | 'close', callback: Callback\): void
+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.
@@ -509,13 +554,13 @@ udp.on('close', () => {
```
-### off\('listening' | 'close'\)
+### off('listening' | 'close')
-off\(type: 'listening' | 'close', callback?: Callback\): void
+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.
->**NOTE**
+>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
@@ -535,22 +580,22 @@ 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 callback. If you do not pass the **callback**, you will cancel listening for all callbacks.
+// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks.
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 callback. If you do not pass the **callback**, you will cancel listening for all callbacks.
+// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks.
udp.off('close', callback2);
udp.off('close');
```
-### on\('error'\)
+### on('error')
-on\(type: 'error', callback: ErrorCallback\): void
+on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
@@ -563,7 +608,6 @@ Enables listening for error events of the UDPSocket connection. This API uses an
| type | string | Yes | Type of the event to subscribe to.
**error**: error event|
| callback | ErrorCallback | Yes | Callback used to return the result. |
-
**Example**
```js
@@ -574,13 +618,13 @@ udp.on('error', err => {
```
-### off\('error'\)
+### off('error')
-off\(type: 'error', callback?: ErrorCallback\): void
+off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
->**NOTE**
+>**NOTE**
>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
@@ -600,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 callback. If you do not pass the **callback**, you will cancel listening for all callbacks.
+// You can pass the callback of the on method to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks.
udp.off('error', callback);
udp.off('error');
```
@@ -668,9 +712,15 @@ Defines information about the socket connection.
| port | number | Yes | Port number. The value ranges from **0** to **65535**. |
| size | number | Yes | Length of the server response message, in bytes. |
+## Description of UDP Error Codes
+
+The UDP error code mapping is in the format of 2301000 + Linux kernel error code.
+
+For details about error codes, see [Socket Error Codes](../errorcodes/errorcode-net-socket.md).
+
## socket.constructTCPSocketInstance
-constructTCPSocketInstance\(\): TCPSocket
+constructTCPSocketInstance(): TCPSocket
Creates a **TCPSocket** object.
@@ -679,7 +729,7 @@ Creates a **TCPSocket** object.
**Return value**
| Type | Description |
- | --------------------------------- | ---------------------- |
+ | :--------------------------------- | :---------------------- |
| [TCPSocket](#tcpsocket) | **TCPSocket** object.|
**Example**
@@ -695,7 +745,7 @@ Defines a TCPSocket connection. Before invoking TCPSocket APIs, you need to call
### bind
-bind\(address: NetAddress, callback: AsyncCallback\): void
+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.
@@ -710,6 +760,12 @@ Binds the IP address and port number. The port number can be specified or random
| address | [NetAddress](#netaddress) | Yes | Destination address. For details, see [NetAddress](#netaddress).|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
**Example**
@@ -727,7 +783,7 @@ tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
### bind
-bind\(address: NetAddress\): Promise
+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.
@@ -744,9 +800,16 @@ Binds the IP address and port number. The port number can be specified or random
**Return value**
| Type | Description |
-| -------------- | ------------------------------------------------------- |
+| :-------------- | :------------------------------------------------------- |
| Promise\ | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -762,10 +825,13 @@ promise.then(() => {
### connect
-connect\(options: TCPConnectOptions, callback: AsyncCallback\): void
+connect(options: TCPConnectOptions, callback: AsyncCallback\): void
Sets up a connection to the specified IP address and port number. This API uses an asynchronous callback to return the result.
+>**NOTE**
+>This API can be called only after **bind** is successfully called.
+
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
@@ -777,6 +843,13 @@ Sets up a connection to the specified IP address and port number. This API uses
| options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCPSocket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -793,7 +866,7 @@ tcp.connect({ address: {address: '192.168.xx.xxx', port: xxxx, family: 1} , time
### connect
-connect\(options: TCPConnectOptions\): Promise
+connect(options: TCPConnectOptions): Promise\
Sets up a connection to the specified IP address and port number. This API uses a promise to return the result.
@@ -810,9 +883,16 @@ Sets up a connection to the specified IP address and port number. This API uses
**Return value**
| Type | Description |
-| -------------- | --------------------------------------------------------- |
+| :-------------- | :--------------------------------------------------------- |
| Promise\ | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -828,12 +908,12 @@ promise.then(() => {
### send
-send\(options: TCPSendOptions, callback: AsyncCallback\): void
+send(options: TCPSendOptions, callback: AsyncCallback\): void
Sends data over a TCPSocket connection. This API uses an asynchronous callback to return the result.
->**NOTE**
->This API can be called only after [connect](#connect) is successfully called.
+>**NOTE**
+>This API can be called only after **connect** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -846,6 +926,13 @@ Sends data over a TCPSocket connection. This API uses an asynchronous callback t
| options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCPSocket connection. For details, see [TCPSendOptions](#tcpsendoptions).|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -870,12 +957,12 @@ promise.then(() => {
### send
-send\(options: TCPSendOptions\): Promise
+send(options: TCPSendOptions): Promise\
Sends data over a TCPSocket connection. This API uses a promise to return the result.
->**NOTE**
->This API can be called only after [connect](#connect) is successfully called.
+>**NOTE**
+>This API can be called only after **connect** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -890,9 +977,16 @@ Sends data over a TCPSocket connection. This API uses a promise to return the re
**Return value**
| Type | Description |
-| -------------- | ------------------------------------------------- |
+| :-------------- | :------------------------------------------------- |
| Promise\ | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -916,7 +1010,7 @@ promise1.then(() => {
### close
-close\(callback: AsyncCallback\): void
+close(callback: AsyncCallback\): void
Closes a TCPSocket connection. This API uses an asynchronous callback to return the result.
@@ -930,6 +1024,11 @@ Closes a TCPSocket connection. This API uses an asynchronous callback to return
| -------- | --------------------- | ---- | ---------- |
| callback | AsyncCallback\ | Yes | Callback used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 201 | Permission denied. |
**Example**
@@ -947,7 +1046,7 @@ tcp.close(err => {
### close
-close\(\): Promise
+close(): Promise\
Closes a TCPSocket connection. This API uses a promise to return the result.
@@ -958,9 +1057,15 @@ Closes a TCPSocket connection. This API uses a promise to return the result.
**Return value**
| Type | Description |
-| -------------- | ----------------------------------------- |
+| :-------------- | :----------------------------------------- |
| Promise\ | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -976,12 +1081,12 @@ promise.then(() => {
### getRemoteAddress
-getRemoteAddress\(callback: AsyncCallback\): void
+getRemoteAddress(callback: AsyncCallback\): void
Obtains the remote address of a socket connection. This API uses an asynchronous callback to return the result.
->**NOTE**
->This API can be called only after [connect](#connect) is successfully called.
+>**NOTE**
+>This API can be called only after **connect** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -993,6 +1098,12 @@ Obtains the remote address of a socket connection. This API uses an asynchronous
| -------- | ------------------------------------------------- | ---- | ---------- |
| callback | AsyncCallback<[NetAddress](#netaddress)> | Yes | Callback used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -1015,12 +1126,12 @@ promise.then(() => {
### getRemoteAddress
-getRemoteAddress\(\): Promise
+getRemoteAddress(): Promise\
Obtains the remote address of a socket connection. This API uses a promise to return the result.
->**NOTE**
->This API can be called only after [connect](#connect) is successfully called.
+>**NOTE**
+>This API can be called only after **connect** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -1029,9 +1140,15 @@ Obtains the remote address of a socket connection. This API uses a promise to re
**Return value**
| Type | Description |
-| ------------------------------------------ | ------------------------------------------ |
+| :------------------------------------------ | :------------------------------------------ |
| Promise<[NetAddress](#netaddress)> | Promise used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 201 | Permission denied. |
+
**Example**
```js
@@ -1053,12 +1170,12 @@ promise1.then(() => {
### getState
-getState\(callback: AsyncCallback\): void
+getState(callback: AsyncCallback\): void
Obtains the status of the TCPSocket connection. This API uses an asynchronous callback to return the result.
->**NOTE**
->This API can be called only after [bind](#bind) or [connect](#connect) is successfully called.
+>**NOTE**
+>This API can be called only after **bind** or **connect** is successfully called.
**Required permissions**: ohos.permission.INTERNET
@@ -1070,6 +1187,11 @@ Obtains the status of the TCPSocket connection. This API uses an asynchronous ca
| -------- | ------------------------------------------------------ | ---- | ---------- |
| callback | AsyncCallback<[SocketStateBase](#socketstatebase)> | Yes | Callback used to return the result.|
+**Error codes**
+
+| ID| Error Message |
+| ------- | ----------------------- |
+| 201 | Permission denied. |
**Example**
@@ -1093,12 +1215,12 @@ promise.then(() => {
### getState
-getState\(\): Promise
+getState(): Promise\