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/reference/apis/js-apis-batteryStatistics.md b/en/application-dev/reference/apis/js-apis-batteryStatistics.md
index 89cd4ab39ee2d9a7c7e0a4f9b03a4755b55b864f..721a432caaf67116a6df882c0e8995e76b893a7e 100644
--- a/en/application-dev/reference/apis/js-apis-batteryStatistics.md
+++ b/en/application-dev/reference/apis/js-apis-batteryStatistics.md
@@ -18,7 +18,7 @@ import batteryStats from '@ohos.batteryStatistics';
getBatteryStats(): Promise
-Obtains the power consumption information list, using a promise to return the result.
+Obtains the power consumption information list. This API uses a promise to return the result.
**System API**: This is a system API.
@@ -34,9 +34,9 @@ Obtains the power consumption information list, using a promise to return the re
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
-| Code| Error Message |
-| -------- | -------------- |
-| 4600101 | Operation failed. Cannot connect to service.|
+| Code | Error Message |
+|---------|---------|
+| 4600101 | Operation failed. Cannot connect to service.|
**Example**
@@ -64,15 +64,15 @@ Obtains the power consumption information list. This API uses an asynchronous ca
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
-| callback | AsyncCallback> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the array of power consumption information obtained. If the operation failed, **err** is an error object.|
+| callback | AsyncCallback> | Yes | Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the array of power consumption information obtained (that is, **Array<[BatteryStatsInfo](#batterystatsinfo)>>**). If the operation failed, **err** is an error object.|
**Error codes**
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
-| Code| Error Message |
-| -------- | -------------- |
-| 4600101 | Operation failed. Cannot connect to service.|
+| Code | Error Message |
+|---------|---------|
+| 4600101 | Operation failed. Cannot connect to service.|
**Example**
@@ -112,9 +112,9 @@ Obtains the power consumption of an application.
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
-| Code| Error Message |
-| -------- | -------------- |
-| 4600101 | Operation failed. Cannot connect to service.|
+| Code | Error Message |
+|---------|---------|
+| 4600101 | Operation failed. Cannot connect to service.|
**Example**
@@ -153,9 +153,9 @@ Obtains the proportion of the power consumption of an application.
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
-| Code| Error Message |
-| -------- | -------------- |
-| 4600101 | Operation failed. Cannot connect to service.|
+| Code | Error Message |
+|---------|---------|
+| 4600101 | Operation failed. Cannot connect to service.|
**Example**
@@ -194,16 +194,16 @@ Obtains the power consumption of a hardware unit according to the consumption ty
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
-| Code| Error Message |
-| -------- | -------------- |
-| 4600101 | Operation failed. Cannot connect to service.|
+| Code | Error Message |
+|---------|---------|
+| 4600101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
var value = batteryStats.getHardwareUnitPowerValue(ConsumptionType.CONSUMPTION_TYPE_SCREEN);
- console.info('battery statistics percent of hardware is: ' + percent);
+ console.info('battery statistics value of hardware is: ' + value);
} catch(err) {
console.error('get battery statistics percent of hardware failed, err: ' + err);
}
@@ -235,15 +235,15 @@ Obtains the proportion of the power consumption of a hardware unit according to
For details about the error codes, see [Thermal Manager Error Codes](../errorcodes/errorcode-batteryStatistics.md).
-| Code| Error Message |
-| -------- | -------------- |
-| 4600101 | Operation failed. Cannot connect to service.|
+| Code | Error Message |
+|---------|---------|
+| 4600101 | Operation failed. Cannot connect to service.|
**Example**
```js
try {
- var value = batteryStats.getHardwareUnitPowerPercent(ConsumptionType.CONSUMPTION_TYPE_SCREEN);
+ var percent = batteryStats.getHardwareUnitPowerPercent(ConsumptionType.CONSUMPTION_TYPE_SCREEN);
console.info('battery statistics percent of hardware is: ' + percent);
} catch(err) {
console.error('get battery statistics percent of hardware failed, err: ' + err);
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 3445952a9c818fad947373508accb50322e8cf59..d86e3904ec9c8789a645fde87492da5f5cd0c250 100644
--- a/en/application-dev/reference/apis/js-apis-net-ethernet.md
+++ b/en/application-dev/reference/apis/js-apis-net-ethernet.md
@@ -114,9 +114,9 @@ ethernet.setIfaceConfig("eth0", {
dnsServers: "1.1.1.1",
domain: "2.2.2.2"
}).then(() => {
- console.log("setIfaceConfig promiss ok ");
+ console.log("setIfaceConfig promise ok ");
}).catch(error => {
- console.log("setIfaceConfig promiss error = " + JSON.stringify(error));
+ console.log("setIfaceConfig promise error = " + JSON.stringify(error));
});
```
@@ -207,15 +207,15 @@ Obtains the configuration of a network interface. This API uses a promise to ret
```js
ethernet.getIfaceConfig("eth0").then((data) => {
- 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));
+ console.log("getIfaceConfig promise mode = " + JSON.stringify(data.mode));
+ console.log("getIfaceConfig promise ipAddr = " + JSON.stringify(data.ipAddr));
+ console.log("getIfaceConfig promise route = " + JSON.stringify(data.route));
+ console.log("getIfaceConfig promise gateway = " + JSON.stringify(data.gateway));
+ console.log("getIfaceConfig promise netMask = " + JSON.stringify(data.netMask));
+ console.log("getIfaceConfig promise dnsServers = " + JSON.stringify(data.dnsServers));
+ console.log("getIfaceConfig promise domain = " + JSON.stringify(data.domain));
}).catch(error => {
- console.log("getIfaceConfig promiss error = " + JSON.stringify(error));
+ console.log("getIfaceConfig promise error = " + JSON.stringify(error));
});
```
@@ -300,9 +300,9 @@ Checks whether a network interface is active. This API uses a promise to return
```js
ethernet.isIfaceActive("eth0").then((data) => {
- console.log("isIfaceActive promiss = " + JSON.stringify(data));
+ console.log("isIfaceActive promise = " + JSON.stringify(data));
}).catch(error => {
- console.log("isIfaceActive promiss error = " + JSON.stringify(error));
+ console.log("isIfaceActive promise error = " + JSON.stringify(error));
});
```
@@ -377,12 +377,12 @@ Obtains the list of all active network interfaces. This API uses a promise to re
```js
ethernet.getAllActiveIfaces().then((data) => {
- console.log("getAllActiveIfaces promiss data.length = " + JSON.stringify(data.length));
+ console.log("getAllActiveIfaces promise data.length = " + JSON.stringify(data.length));
for (let i = 0; i < data.length; i++) {
- console.log("getAllActiveIfaces promiss = " + JSON.stringify(data[i]));
+ console.log("getAllActiveIfaces promise = " + JSON.stringify(data[i]));
}
}).catch(error => {
- console.log("getAllActiveIfaces promiss error = " + JSON.stringify(error));
+ console.log("getAllActiveIfaces promise error = " + JSON.stringify(error));
});
```
diff --git a/en/application-dev/reference/apis/js-apis-observer.md b/en/application-dev/reference/apis/js-apis-observer.md
index 2d56d02d2ec4e0f2117266569cb5bfd905f1b338..3c46e47479de6cacc6a0a2613f0aa422aad9aff8 100644
--- a/en/application-dev/reference/apis/js-apis-observer.md
+++ b/en/application-dev/reference/apis/js-apis-observer.md
@@ -10,7 +10,7 @@ The **observer** module provides event subscription management functions. You ca
## Modules to Import
```
-import observer from '@ohos.telephony.observer'
+import observer from '@ohos.telephony.observer';
```
## observer.on('networkStateChange')
@@ -31,7 +31,6 @@ Registers an observer for network status change events. This API uses an asynchr
| callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | Yes | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -45,7 +44,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('networkStateChange', data =>{
+observer.on('networkStateChange', data => {
console.log("on networkStateChange, data:" + JSON.stringify(data));
});
```
@@ -70,7 +69,6 @@ Registers an observer for network status change events of the SIM card in the sp
| callback | Callback\<[NetworkState](js-apis-radio.md#networkstate)\> | Yes | Callback used to return the result. For details, see [NetworkState](js-apis-radio.md#networkstate).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -84,7 +82,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('networkStateChange', {slotId: 0}, data =>{
+observer.on('networkStateChange', {slotId: 0}, data => {
console.log("on networkStateChange, data:" + JSON.stringify(data));
});
```
@@ -145,7 +143,6 @@ Registers an observer for signal status change events. This API uses an asynchro
| callback | Callback\> | Yes | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -159,7 +156,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('signalInfoChange', data =>{
+observer.on('signalInfoChange', data => {
console.log("on signalInfoChange, data:" + JSON.stringify(data));
});
```
@@ -182,7 +179,6 @@ Registers an observer for signal status change events of the SIM card in the spe
| callback | Callback\> | Yes | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -196,7 +192,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('signalInfoChange', {slotId: 0}, data =>{
+observer.on('signalInfoChange', {slotId: 0}, data => {
console.log("on signalInfoChange, data:" + JSON.stringify(data));
});
```
@@ -222,7 +218,6 @@ Unregisters the observer for signal status change events. This API uses an async
| callback | Callback\> | No | Callback used to return the result. For details, see [SignalInformation](js-apis-radio.md#signalinformation).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -244,6 +239,125 @@ observer.off('signalInfoChange', callback);
observer.off('signalInfoChange');
```
+## observer.on('cellInfoChange')8+
+
+on\(type: \'cellInfoChange\', callback: Callback\): void;
+
+Registers an observer for cell information change events. This API uses an asynchronous callback to return the result.
+
+**System API**: This is a system API.
+
+**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
+
+**System capability**: SystemCapability.Telephony.StateRegistry
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------------------------- | ---- |------------------------------------------------------------|
+| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**. |
+| callback | Callback\<[CellInformation](js-apis-radio.md#cellinformation8)\> | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| -------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 8300001 | Invalid parameter value. |
+| 8300002 | Operation failed. Cannot connect to service. |
+| 8300003 | System internal error. |
+| 8300999 | Unknown error code. |
+
+**Example**
+
+```js
+observer.on('cellInfoChange', data => {
+ console.log("on cellInfoChange, data:" + JSON.stringify(data));
+});
+```
+
+
+## observer.on('cellInfoChange')8+
+
+on\(type: \'cellInfoChange\', options: { slotId: number }, callback: Callback\): void;
+
+Registers an observer for signal status change events of the SIM card in the specified slot. This API uses an asynchronous callback to return the execution result.
+
+**System API**: This is a system API.
+
+**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
+
+**System capability**: SystemCapability.Telephony.StateRegistry
+
+**Parameters**
+
+| Name| Type | Mandatory| Description |
+| ------ |--------------------------------------------------| ---- |------------------------------------------------------------|
+| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**. |
+| slotId | number | Yes | Card slot ID. - **0**: card slot 1 - **1**: card slot 2 |
+| callback | Callback\<[CellInformation](js-apis-radio.md#cellinformation8)\> | Yes | Callback used to return the result.|
+
+**Error codes**
+
+| ID| Error Message |
+| -------- | -------------------------------------------- |
+| 201 | Permission denied. |
+| 401 | Parameter error. |
+| 8300001 | Invalid parameter value. |
+| 8300002 | Operation failed. Cannot connect to service. |
+| 8300003 | System internal error. |
+| 8300999 | Unknown error code. |
+
+**Example**
+
+```js
+observer.on('cellInfoChange', {slotId: 0}, data => {
+ console.log("on cellInfoChange, data:" + JSON.stringify(data));
+});
+```
+
+
+## observer.off('cellInfoChange')8+
+
+off\(type: \'cellInfoChange\', callback?: Callback\): void;
+
+Unregisters the observer for cell information change events. This API uses an asynchronous callback to return the result.
+
+>**NOTE**
+>
+>You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
+
+**System API**: This is a system API.
+
+**System capability**: SystemCapability.Telephony.StateRegistry
+
+**Parameters**
+
+| Name | Type | Mandatory| Description |
+| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
+| type | string | Yes | Cell information change event. This field has a fixed value of **cellInfoChange**. |
+| callback | Callback\<[CellInformation](js-apis-radio.md#cellinformation8)\> | No | Callback used to return the result.|
+
+| ID| Error Message |
+| -------- | -------------------------------------------- |
+| 401 | Parameter error. |
+| 8300001 | Invalid parameter value. |
+| 8300002 | Operation failed. Cannot connect to service. |
+| 8300003 | System internal error. |
+| 8300999 | Unknown error code. |
+
+**Example**
+
+```js
+let callback = data => {
+ console.log("on cellInfoChange, data:" + JSON.stringify(data));
+}
+observer.on('cellInfoChange', 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.
+observer.off('cellInfoChange', callback);
+observer.off('cellInfoChange');
+```
## observer.on('callStateChange')
@@ -261,7 +375,6 @@ Registers an observer for call status change events. This API uses an asynchrono
| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | Yes | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call. **number**: phone number.|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -274,7 +387,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('callStateChange', value =>{
+observer.on('callStateChange', value => {
console.log("on callStateChange, state:" + value.state + ", number:" + value.number);
});
```
@@ -297,7 +410,6 @@ Registers an observer for call status change events. This API uses an asynchrono
| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | Yes | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call. **number**: phone number.|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -310,7 +422,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('callStateChange', {slotId: 0}, value =>{
+observer.on('callStateChange', {slotId: 0}, value => {
console.log("on callStateChange, state:" + value.state + ", number:" + value.number);
});
```
@@ -336,7 +448,6 @@ Unregisters the observer for call status change events. This API uses an asynchr
| callback | Callback\<{ state: [CallState](js-apis-call.md#callstate), number: string }\> | No | Callback function. For details, see [CallState](js-apis-call.md#callstate) in call. **number**: phone number.|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -375,7 +486,6 @@ Registers an observer for connection status change events of the cellular data l
| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | Yes | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -388,7 +498,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('cellularDataConnectionStateChange', value =>{
+observer.on('cellularDataConnectionStateChange', value => {
console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network);
});
```
@@ -411,7 +521,6 @@ Registers an observer for connection status change events of the cellular data l
| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | Yes | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -424,7 +533,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('cellularDataConnectionStateChange', {slotId: 0}, value =>{
+observer.on('cellularDataConnectionStateChange', {slotId: 0}, value => {
console.log("on cellularDataConnectionStateChange, state:" + value.state + ", network:" + value.network);
});
```
@@ -450,7 +559,6 @@ Unregisters the observer for connection status change events of the cellular dat
| callback | Callback\<{ state: [DataConnectState](js-apis-telephony-data.md#dataconnectstate), network: [RatType](js-apis-radio.md#radiotechnology) }\> | No | Callback used to return the result. For details, see [DataConnectState](js-apis-telephony-data.md#dataconnectstate) and [RadioTechnology](js-apis-radio.md#radiotechnology).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -489,7 +597,6 @@ Registers an observer for the uplink and downlink data flow status change events
| callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | Yes | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -502,7 +609,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('cellularDataFlowChange', data =>{
+observer.on('cellularDataFlowChange', data => {
console.log("on networkStateChange, data:" + JSON.stringify(data));
});
```
@@ -525,7 +632,6 @@ Registers an observer for the uplink and downlink data flow status change events
| callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | Yes | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -538,7 +644,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('cellularDataFlowChange', {slotId: 0}, data =>{
+observer.on('cellularDataFlowChange', {slotId: 0}, data => {
console.log("on cellularDataFlowChange, data:" + JSON.stringify(data));
});
```
@@ -564,7 +670,6 @@ Unregisters the observer for the uplink and downlink data flow status change eve
| callback | Callback\<[DataFlowType](js-apis-telephony-data.md#dataflowtype)\> | No | Callback used to return the result. For details, see [DataFlowType](js-apis-telephony-data.md#dataflowtype).|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -603,7 +708,6 @@ Registers an observer for SIM card status change events. This API uses an asynch
| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -616,7 +720,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('simStateChange', data =>{
+observer.on('simStateChange', data => {
console.log("on simStateChange, data:" + JSON.stringify(data));
});
```
@@ -639,7 +743,6 @@ Registers an observer for status change events of the SIM card in the specified
| callback | Callback\<[SimStateData](#simstatedata7)\> | Yes | Callback used to return the result.|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -652,7 +755,7 @@ For details about the following error codes, see [Telephony Error Codes](../../r
**Example**
```js
-observer.on('simStateChange', {slotId: 0}, data =>{
+observer.on('simStateChange', {slotId: 0}, data => {
console.log("on simStateChange, data:" + JSON.stringify(data));
});
```
@@ -678,7 +781,6 @@ Unregisters the observer for SIM card status change events. This API uses an asy
| callback | Callback\<[SimStateData](#simstatedata7)\> | No | Callback used to return the result.|
**Error codes**
-For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md).
| ID| Error Message |
| -------- | -------------------------------------------- |
@@ -732,6 +834,6 @@ Enumerates SIM card types and states.
| Name | Type | Mandatory| Description |
| ------------------- | ----------------------------------- | ---- | -------------------------------------------------------- |
-| type | [CardType](js-apis-sim.md#cardtype) | Yes | SIM card type. For details, see [CardType](js-apis-sim.md#cardtype).|
-| state | [SimState](js-apis-sim.md#simstate) | Yes | SIM card status. For details, see [SimState](js-apis-sim.md#simstate).|
+| type | [CardType](js-apis-sim.md#cardtype7) | Yes | SIM card type.|
+| state | [SimState](js-apis-sim.md#simstate) | Yes | SIM card state.|
| reason8+ | [LockReason](#lockreason8) | Yes | SIM card lock type. |
diff --git a/en/application-dev/reference/apis/js-apis-system-battery.md b/en/application-dev/reference/apis/js-apis-system-battery.md
index d673a500027654075ff330c916cd22add25abaf6..efeb9caec59a04362b80c6f3502dc5a34b8e7f34 100644
--- a/en/application-dev/reference/apis/js-apis-system-battery.md
+++ b/en/application-dev/reference/apis/js-apis-system-battery.md
@@ -46,6 +46,8 @@ battery.getStatus({
Object that contains the API calling result.
+**System capability**: SystemCapability.PowerManager.BatteryManager.Core
+
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------- | ---- | ------------------------------------------------------------ |
| success | (data: [BatteryResponse](#batteryresponse)) => void | No | Called when API call is successful. **data** is a return value of the [BatteryResponse](#batteryresponse) type.|
@@ -56,7 +58,9 @@ Object that contains the API calling result.
Defines a response that returns the charging status and remaining power of the device.
-| Name| Type| Description|
-| -------- | -------- | -------- |
-| charging | boolean | Whether the battery is being charged.|
-| level | number | Current battery level, which ranges from **0.00** to **1.00**.|
+**System capability**: SystemCapability.PowerManager.BatteryManager.Core
+
+| Name| Type| Readable| Writable| Description|
+| -------- | -------- | -------- | -------- | -------- |
+| charging | boolean | Yes| No| Whether the battery is being charged.|
+| level | number | Yes| No| Current battery level, which ranges from **0.00** to **1.00**.|
diff --git a/en/application-dev/reference/apis/js-apis-system-brightness.md b/en/application-dev/reference/apis/js-apis-system-brightness.md
index 939e7d7021bc8f93ad7359004de58f525feeee05..3cc0779edf610eb39cda868abc84d353c6b05dc6 100644
--- a/en/application-dev/reference/apis/js-apis-system-brightness.md
+++ b/en/application-dev/reference/apis/js-apis-system-brightness.md
@@ -45,7 +45,7 @@ Obtains the current screen brightness.
## brightness.setValue
-etValue(options?: SetBrightnessOptions): void
+setValue(options?: SetBrightnessOptions): void
Sets the screen brightness.
@@ -74,7 +74,7 @@ Sets the screen brightness.
## brightness.getMode
-getMode(options?: GetBrightnessModeOptions: void
+getMode(options?: GetBrightnessModeOptions): void
Obtains the screen brightness adjustment mode.
@@ -161,67 +161,81 @@ Sets whether to always keep the screen on. Call this API in **onShow()**.
Defines the options for obtaining the screen brightness.
+**System capability**: SystemCapability.PowerManager.DisplayPowerManager
+
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
| success | (data: [BrightnessResponse](#brightnessresponse)) => void | No | Called when API call is successful. **data** is a return value of the [BrightnessResponse](#brightnessresponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
-| complete | () => void | No | Called when API call is complete. |
+| complete | () => void | No | Called when the API call is complete. |
## SetBrightnessOptions
Defines the options for setting the screen brightness.
+**System capability**: SystemCapability.PowerManager.DisplayPowerManager
+
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------------ |
| value | number | Yes | Screen brightness. The value is an integer ranging from **1** to **255**. - If the value is less than or equal to **0**, value **1** will be used. - If the value is greater than **255**, value **255** will be used. - If the value contains decimals, the integral part of the value will be used. For example, if value **8.1** is set, value **8** will be used.|
-| success | () => void | No | Called when API call is successful. |
+| success | () => void | No | Callback upon a successful API call. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
-| complete | () => void | No | Called when API call is complete. |
+| complete | () => void | No | Called when the API call is complete. |
## BrightnessResponse
Defines a response that returns the screen brightness.
-| Parameter| Type | Description|
-| -------- | -------- | -------- |
-| value | number | Screen brightness. The value ranges from 1 to 255.|
+**System capability**: SystemCapability.PowerManager.DisplayPowerManager
+
+| Name| Type| Readable| Writable| Description|
+| -------- | -------- | -------- | -------- | -------- |
+| value | number | Yes| No| Screen brightness. The value ranges from **1** to **255**.|
## GetBrightnessModeOptions
Defines the options for obtaining the screen brightness mode.
+**System capability**: SystemCapability.PowerManager.DisplayPowerManager
+
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| success | (data: [BrightnessModeResponse](#brightnessmoderesponse)) => void | No | Called when API call is successful. **data** is a return value of the [BrightnessModeResponse](#brightnessmoderesponse) type.|
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code. |
-| complete | () => void | No | Called when API call is complete. |
+| complete | () => void | No | Called when the API call is complete. |
## SetBrightnessModeOptions
Defines the options for setting the screen brightness mode.
+**System capability**: SystemCapability.PowerManager.DisplayPowerManager
+
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------------------------------ |
| mode | number | Yes | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
-| success | () => void | No | Called when API call is successful. |
+| success | () => void | No | Callback upon a successful API call. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
-| complete | () => void | No | Called when API call is complete. |
+| complete | () => void | No | Called when the API call is complete. |
## BrightnessModeResponse
Defines a response that returns the screen brightness mode.
-| Name| Type | Description|
-| -------- | -------- | -------- |
-| mode | number | The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
+**System capability**: SystemCapability.PowerManager.DisplayPowerManager
+
+| Name| Type| Readable| Writable| Description|
+| -------- | -------- | -------- | -------- | -------- |
+| mode | number | Yes| No| The value **0** indicates the manual adjustment mode, and the value **1** indicates the automatic adjustment mode.|
## SetKeepScreenOnOptions
Defines the options for setting the screen to be steady on.
+**System capability**: SystemCapability.PowerManager.DisplayPowerManager
+
| Name | Type | Mandatory| Description |
| ------------ | ------------------------------------ | ---- | ------------------------------------------------------ |
| keepScreenOn | boolean | Yes | The value **true** means to keep the screen steady on, and the value **false** indicates the opposite. |
-| success | () => void | No | Called when API call is successful. |
+| success | () => void | No | Callback upon a successful API call. |
| fail | (data: string, code: number) => void | No | Called when API call has failed. **data** indicates the error information, and **code** indicates the error code.|
-| complete | () => void | No | Called when API call is complete. |
+| complete | () => void | No | Called when the API call is complete. |
diff --git a/en/application-dev/reference/apis/js-apis-system-fetch.md b/en/application-dev/reference/apis/js-apis-system-fetch.md
index 6829c569a3471855c403a6bfad5e80bdd18afecc..6144d903c19116e693841e5f4a55840aac43e68b 100644
--- a/en/application-dev/reference/apis/js-apis-system-fetch.md
+++ b/en/application-dev/reference/apis/js-apis-system-fetch.md
@@ -1,9 +1,8 @@
# @system.fetch (Data Request)
> **NOTE**
->
> - The APIs of this module are no longer maintained since API version 6. You are advised to use [`@ohos.net.http`](js-apis-http.md) instead.
->
+>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
@@ -15,7 +14,7 @@ import fetch from '@system.fetch';
```
-## fetch.fetch
+## fetch.fetch3+
fetch(Object): void
@@ -31,9 +30,9 @@ Obtains data through a network.
| header | Object | No| Request header.|
| method | string | No| Request method. The default value is **GET**. The value can be **OPTIONS**, **GET**, **HEAD**, **POST**, **PUT**, **DELETE **or **TRACE**.|
| responseType | string | No| Response type. The return type can be text or JSON. By default, the return type is determined based on **Content-Type** in the header returned by the server. For details, see return values in the **success** callback.|
-| success | Function | No| Called when data is obtained successfully. The return value is [FetchResponse](#fetchresponse). |
-| fail | Function | No| Called when data failed to be obtained.|
-| complete | Function | No| Called when the execution is complete.|
+| success | Function | No| Called when the API call is successful. The return value is defined by [FetchResponse](#fetchresponse).|
+| fail | Function | No| Called when API call has failed.|
+| complete | Function | No| Called when the API call is complete.|
**Table 1** Mapping between data and Content-Type
@@ -46,11 +45,11 @@ Obtains data through a network.
## FetchResponse
-| Name| Type| Description|
-| -------- | -------- | -------- |
-| code | number | Server status code.|
-| data | string \| Object | The type of the returned data is determined by **responseType**. For details, see the mapping between **responseType** and **data** in **success** callback.|
-| headers | Object | All headers in the response from the server.|
+| Name| Type| Readable| Writable| Description|
+| -------- | -------- | -------- | -------- | -------- |
+| code | number | Yes| No| Server status code.|
+| data | string \| Object | Yes| No| The type of the returned data is determined by **responseType**. For details, see the mapping between **responseType** and **data** in **success** callback.|
+| headers | Object | Yes| No| All headers in the response from the server.|
**Table 2** Mapping between responseType and data in success callback
@@ -85,7 +84,7 @@ export default {
```
-> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> **NOTE**
> HTTPS is supported by default. To support HTTP, you need to add **"network"** to the **config.json** file, and set the attribute **"cleartextTraffic"** to **true**. That is:
>
> ```
diff --git a/en/application-dev/reference/apis/js-apis-system-network.md b/en/application-dev/reference/apis/js-apis-system-network.md
index e012487feefe73e79738c570e4e2ebda9ad23919..5fe6e782edc352c4d49377b4e8d9a4343d8435a6 100644
--- a/en/application-dev/reference/apis/js-apis-system-network.md
+++ b/en/application-dev/reference/apis/js-apis-system-network.md
@@ -1,8 +1,8 @@
# @system.network (Network State)
> **NOTE**
->
-> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.telephony.observer`](js-apis-observer.md) instead.
+> - The APIs of this module are no longer maintained since API version 7. You are advised to use [`@ohos.telephony.observer`](js-apis-observer.md).
+>
> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version.
@@ -31,17 +31,17 @@ Obtains the network type.
**Parameters**
-| Name | Type | Mandatory | Description |
+| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| success | Function | No | Called when the execution is successful. The return value is [NetworkResponse](#networkresponse). |
-| fail | Function | No | Called when the operation fails. |
-| complete | Function | No | Called when the execution is complete |
+| success | Function | No| Called when the API call is successful. The return value is defined by [NetworkResponse](#networkresponse).|
+| fail | Function | No| Called when API call has failed.|
+| complete | Function | No| Called when the API call is complete.|
-Return value of the **fail** callback:
+One of the following error codes will be returned if the API call has failed.
-| Error Code | Description |
+| Error Code| Description|
| -------- | -------- |
-| 602 | The current permission is not declared. |
+| 602 | The current permission is not declared.|
**Example**
@@ -71,17 +71,17 @@ Listens to the network connection state. If this method is called multiple times
**Parameters**
-| Name | Type | Mandatory | Description |
+| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| success | Function | No | Called when the network connection state changes |
-| fail | Function | No | Called when the multimedia volume fails to be obtained. |
+| success | Function | No| Called when the network state changes. The return value is defined by [NetworkResponse](#networkresponse).|
+| fail | Function | No| Called when API call has failed.|
-Return value of the **fail** callback:
+One of the following error codes will be returned if the API call has failed.
-| Error Code | Description |
+| Error Code| Description|
| -------- | -------- |
-| 602 | The current permission is not declared. |
-| 200 | The subscription fails. |
+| 602 | The current permission is not declared.|
+| 200 | Subscription failed.|
**Example**
@@ -119,9 +119,12 @@ export default {
}
```
+
## NetworkResponse
-| Parameter | Type | Description |
-| -------- | -------- | -------- |
-| metered | boolean | Whether the billing is based on the data volume. |
-| type | string | Network type. The value can be **2G**, **3G**, **4G**, **5G**, **WiFi**, or **none**. |
\ No newline at end of file
+**System capability**: SystemCapability.Communication.NetManager.Core
+
+| Name| Type| Mandatory| Description|
+| -------- | -------- | -------- | -------- |
+| metered | boolean | No|Whether to charge by traffic.|
+| type | string | Yes|Network type. The value can be **2G**, **3G**, **4G**, **5G**, **WiFi**, or **none**.|
diff --git a/en/application-dev/reference/apis/js-apis-update.md b/en/application-dev/reference/apis/js-apis-update.md
index ffb07ba4f21cc5f154bcf25062f86845c97577dc..923baae8383344c8b0bb252bd59c67aca26d04bc 100644
--- a/en/application-dev/reference/apis/js-apis-update.md
+++ b/en/application-dev/reference/apis/js-apis-update.md
@@ -8,8 +8,10 @@ There are two types of updates: SD card update and over the air (OTA) update.
- The OTA update depends on the server deployed by the device manufacturer for managing update packages. The OTA server IP address is passed by the caller. The request interface is fixed and developed by the device manufacturer.
> **NOTE**
-> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
-> - The APIs provided by this module are system APIs.
+>
+> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
+>
+> The APIs provided by this module are system APIs.
## Modules to Import
@@ -2034,7 +2036,7 @@ Enumerates update states.
| WAITING_INSTALL | 30 | Waiting for installation. |
| UPDATING | 31 | Updating. |
| WAITING_APPLY | 40 | Waiting for applying the update. |
-| APPLYING | 21 | Applying the update. |
+| APPLYING | 41 | Applying the update. |
| UPGRADE_SUCCESS | 50 | Update succeeded.|
| UPGRADE_FAIL | 51 | Update failed.|
@@ -2056,7 +2058,7 @@ Enumerates event IDs.
| Name | Value | Description |
| ---------------------- | ---------- | ------ |
-| EVENT_TASK_BASE | 0x01000000 | Task event. |
+| EVENT_TASK_BASE | EventClassify.TASK | Task event. |
| EVENT_TASK_RECEIVE | 0x01000001 | Task received. |
| EVENT_TASK_CANCEL | 0x01000010 | Task cancelled. |
| EVENT_DOWNLOAD_WAIT | 0x01000011 | Waiting for download. |
diff --git a/en/application-dev/reference/apis/js-apis-usb-deprecated.md b/en/application-dev/reference/apis/js-apis-usb-deprecated.md
index 9e7fe19db49c7863967ba386f63dfdeeef4b12cc..f5c4bc2d05b1ac5e085f573c1730882afc38a03c 100644
--- a/en/application-dev/reference/apis/js-apis-usb-deprecated.md
+++ b/en/application-dev/reference/apis/js-apis-usb-deprecated.md
@@ -1,11 +1,12 @@
-# @ohos.usb (USB Management)
+# @ohos.usb (USB)
The **usb** module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control.
-> **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.
-> This module is deprecated since API version 9. You are advised to use [`@ohos.usbManager`](js-apis-usbManager.md) instead.
+>
+> The APIs provided by this module are no longer maintained since API version 9. You are advised to use [`@ohos.usbManager`](js-apis-usbManager.md).
## Modules to Import
@@ -25,13 +26,13 @@ Obtains the USB device list.
| Type | Description |
| ---------------------------------------------------- | ------- |
-| Array<Readonly<[USBDevice](#usbdevice)>> | Device information list.|
+| Array<Readonly<[USBDevice](#usbdevice)>> | USB device list.|
**Example**
```js
let devicesList = usb.getDevices();
-console.log(`devicesList = ${JSON.stringify(devicesList)}`);
+console.log(`devicesList = ${devicesList}`);
// devicesList is a list of USB devices.
// A simple example of devicesList is provided as follows:
[
@@ -110,7 +111,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
```js
let devicepipe= usb.connectDevice(device);
-console.log(`devicepipe = ${JSON.stringify(devicepipe)}`);
+console.log(`devicepipe = ${devicepipe}`);
```
## usb.hasRight
@@ -131,7 +132,7 @@ Checks whether the application has the permission to access the device.
| Type| Description|
| -------- | -------- |
-| boolean | The value **true** indicates that the application has the permission to access the device, and the value **false** indicates the opposite.|
+| boolean | Returns **true** if the application has the permission to access the device; returns **false** otherwise.|
**Example**
@@ -145,7 +146,7 @@ console.log(bool);
requestRight(deviceName: string): Promise<boolean>
-Requests the temporary permission for the application to access the USB device. This API uses a promise to return the result.
+Requests the temporary permission for the application to access a USB device. This API uses a promise to return the result.
**System capability**: SystemCapability.USB.USBManager
@@ -159,14 +160,14 @@ Requests the temporary permission for the application to access the USB device.
| Type| Description|
| -------- | -------- |
-| Promise<boolean> | Promise used to return the result. The value **true** indicates that the temporary device access permissions are granted, and the value **false** indicates the opposite.|
+| Promise<boolean> | Promise used to return the result. The value **true** indicates that the temporary device access permissions are granted; and the value **false** indicates the opposite.|
**Example**
```js
let devicesName="1-1";
usb.requestRight(devicesName).then((ret) => {
- console.log(`requestRight = ${JSON.stringify(ret)}`);
+ console.log(`requestRight = ${ret}`);
});
```
@@ -192,7 +193,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| Type| Description|
| -------- | -------- |
-| number | The value **0** indicates that the USB interface is successfully claimed, and an error code indicates the opposite.|
+| number | Returns **0** if the USB interface is successfully claimed; returns an error code otherwise.|
**Example**
@@ -222,7 +223,7 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c
| Type| Description|
| -------- | -------- |
-| number | The value **0** indicates that the USB interface is successfully released, and an error code indicates the opposite.|
+| number | Returns **0** if the USB interface is successfully released; returns an error code otherwise.|
**Example**
@@ -252,7 +253,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| Type| Description|
| -------- | -------- |
-| number | The value **0** indicates that the USB configuration is successfully set, and an error code indicates the opposite.|
+| number | Returns **0** if the USB configuration is successfully set; returns an error code otherwise.|
**Example**
@@ -282,7 +283,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| Type| Description|
| -------- | -------- |
-| number | The value **0** indicates that the USB interface is successfully set, and an error code indicates the opposite.|
+| number | Returns **0** if the USB interface is successfully set; returns an error code otherwise.|
**Example**
@@ -311,7 +312,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| Type| Description|
| -------- | -------- |
-| Uint8Array | The return value is the raw USB descriptor if the operation is successful, or **undefined** if the operation has failed.|
+| Uint8Array | Returns the raw USB descriptor if the operation is successful; returns **undefined** otherwise.|
**Example**
@@ -339,7 +340,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| Type | Description |
| ------ | -------------------- |
-| number | The return value is the file descriptor of the USB device if the operation is successful, or **-1** if the operation has failed.|
+| number | Returns the file descriptor of the USB device if the operation is successful; returns **-1** otherwise.|
**Example**
@@ -374,8 +375,9 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
-usb.controlTransfer(devicepipe, USBControlParams).then((ret) => {
- console.log(`controlTransfer = ${JSON.stringify(ret)}`);
+let param = new usb.USBControlParams();
+usb.controlTransfer(devicepipe, param).then((ret) => {
+ console.log(`controlTransfer = ${ret}`);
})
```
@@ -411,7 +413,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
- console.log(`bulkTransfer = ${JSON.stringify(ret)}`);
+ console.log(`bulkTransfer = ${ret}`);
});
```
@@ -435,7 +437,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
| Type| Description|
| -------- | -------- |
-| number | The value **0** indicates that the USB device pipe is closed successfully, and an error code indicates the opposite.|
+| number | Returns **0** if the USB device pipe is closed successfully; returns an error code otherwise.|
**Example**
@@ -498,7 +500,7 @@ Converts the USB function list in the numeric mask format to a string in Device
**Example**
```js
-let funcs = ACM | ECM;
+let funcs = usb.ACM | usb.ECM;
let ret = usb.usbFunctionsToString(funcs);
```
@@ -527,7 +529,7 @@ Sets the current USB function list in Device mode.
**Example**
```js
-let funcs = HDC;
+let funcs = usb.HDC;
let ret = usb.setCurrentFunctions(funcs);
```
@@ -630,7 +632,12 @@ Sets the role types supported by a specified port, which can be **powerRole** (f
**Example**
```js
-let ret = usb.getSupportedModes(0);
+let portId = 1;
+usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
+ console.info('usb setPortRoles successfully.');
+}).catch(err => {
+ console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
+});
```
## USBEndpoint
@@ -639,16 +646,16 @@ Represents the USB endpoint from which data is sent or received. You can obtain
**System capability**: SystemCapability.USB.USBManager
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| address | number | Yes | Endpoint address. |
-| attributes | number | Yes | Endpoint attributes. |
-| interval | number | Yes | Endpoint interval. |
-| maxPacketSize | number | Yes | Maximum size of data packets on the endpoint. |
-| direction | [USBRequestDirection](#usbrequestdirection) | Yes | Endpoint direction. |
-| number | number | Yes | Endpoint number. |
-| type | number | Yes | Endpoint type. |
-| interfaceId | number | Yes | Unique ID of the interface to which the endpoint belongs.|
+| Name | Type | Mandatory | Description |
+| ------------- | ------------------------------------------- | ------------- |------------ |
+| address | number | Yes |Endpoint address. |
+| attributes | number | Yes |Endpoint attributes. |
+| interval | number | Yes |Endpoint interval. |
+| maxPacketSize | number | Yes |Maximum size of data packets on the endpoint. |
+| direction | [USBRequestDirection](#usbrequestdirection) | Yes |Endpoint direction. |
+| number | number | Yes |Endpoint number. |
+| type | number | Yes |Endpoint type. |
+| interfaceId | number | Yes |Unique ID of the interface to which the endpoint belongs.|
## USBInterface
@@ -656,15 +663,15 @@ Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **U
**System capability**: SystemCapability.USB.USBManager
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| id | number | Yes | Unique ID of the USB interface. |
-| protocol | number | Yes | Interface protocol. |
-| clazz | number | Yes | Device type. |
-| subClass | number | Yes | Device subclass. |
-| alternateSetting | number | Yes | Settings for alternating between descriptors of the same USB interface.|
-| name | string | Yes | Interface name. |
-| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes | Endpoints that belong to the USB interface. |
+| Name | Type | Mandatory |Description |
+| ---------------- | ---------------------------------------- | ------------- |--------------------- |
+| id | number | Yes |Unique ID of the USB interface. |
+| protocol | number | Yes |Interface protocol. |
+| clazz | number | Yes |Device type. |
+| subClass | number | Yes |Device subclass. |
+| alternateSetting | number | Yes |Settings for alternating between descriptors of the same USB interface.|
+| name | string | Yes |Interface name. |
+| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes |Endpoints that belong to the USB interface. |
## USBConfig
@@ -672,15 +679,15 @@ Represents the USB configuration. One [USBDevice](#usbdevice) can contain multip
**System capability**: SystemCapability.USB.USBManager
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| id | number | Yes | Unique ID of the USB configuration. |
-| attributes | number | Yes | Configuration attributes. |
-| maxPower | number | Yes | Maximum power consumption, in mA. |
-| name | string | Yes | Configuration name, which can be left empty. |
-| isRemoteWakeup | boolean | Yes | Support for remote wakeup.|
-| isSelfPowered | boolean | Yes | Support for independent power supplies.|
-| interfaces | Array <[USBInterface](#usbinterface)> | Yes | Supported interface attributes. |
+| Name | Type | Mandatory |Description |
+| -------------- | ------------------------------------------------ | --------------- |----------- |
+| id | number | Yes |Unique ID of the USB configuration. |
+| attributes | number | Yes |Configuration attributes. |
+| maxPower | number | Yes |Maximum power consumption, in mA. |
+| name | string | Yes |Configuration name, which can be left empty. |
+| isRemoteWakeup | boolean | Yes |Support for remote wakeup.|
+| isSelfPowered | boolean | Yes |Support for independent power supplies.|
+| interfaces | Array <[USBInterface](#usbinterface)> | Yes |Supported interface attributes. |
## USBDevice
@@ -688,21 +695,21 @@ Represents the USB device information.
**System capability**: SystemCapability.USB.USBManager
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| busNum | number | Yes | Bus address. |
-| devAddress | number | Yes | Device address. |
-| serial | string | Yes | Sequence number. |
-| name | string | Yes | Device name. |
-| manufacturerName | string | Yes | Device manufacturer. |
-| productName | string | Yes | Product name. |
-| version | string | Yes | Version number. |
-| vendorId | number | Yes | Vendor ID. |
-| productId | number | Yes | Product ID. |
-| clazz | number | Yes | Device class. |
-| subClass | number | Yes | Device subclass. |
-| protocol | number | Yes | Device protocol code. |
-| configs | Array<[USBConfig](#usbconfig)> | Yes | Device configuration descriptor information.|
+| Name | Type | Mandatory |Description |
+| ---------------- | ------------------------------------ | ---------- |---------- |
+| busNum | number | Yes |Bus address. |
+| devAddress | number | Yes |Device address. |
+| serial | string | Yes |Sequence number. |
+| name | string | Yes |Device name. |
+| manufacturerName | string | Yes |Device manufacturer. |
+| productName | string | Yes |Product name. |
+| version | string | Yes |Version. |
+| vendorId | number | Yes |Vendor ID. |
+| productId | number | Yes |Product ID. |
+| clazz | number | Yes |Device class. |
+| subClass | number | Yes |Device subclass. |
+| protocol | number | Yes |Device protocol code. |
+| configs | Array<[USBConfig](#usbconfig)> | Yes |Device configuration descriptor information.|
## USBDevicePipe
@@ -710,10 +717,10 @@ Represents a USB device pipe, which is used to determine a USB device.
**System capability**: SystemCapability.USB.USBManager
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| busNum | number | Yes | Bus address.|
-| devAddress | number | Yes | Device address.|
+| Name | Type | Mandatory |Description |
+| ---------- | ------ | ----- |----- |
+| busNum | number | Yes |Bus address.|
+| devAddress | number | Yes |Device address.|
## USBControlParams
@@ -721,14 +728,14 @@ Represents control transfer parameters.
**System capability**: SystemCapability.USB.USBManager
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| request | number | Yes | Request type. |
-| target | [USBRequestTargetType](#usbrequesttargettype) | Yes | Request target type. |
-| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes | Control request type. |
-| value | number | Yes | Request parameter value. |
-| index | number | Yes | Index of the request parameter value.|
-| data | Uint8Array | Yes | Buffer for writing or reading data. |
+| Name | Type | Mandatory|Description |
+| ------- | ----------------------------------------------- | ---------------- |---------------- |
+| request | number | Yes |Request type. |
+| target | [USBRequestTargetType](#usbrequesttargettype) | Yes |Request target type. |
+| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes |Control request type. |
+| value | number | Yes |Request parameter value. |
+| index | number | Yes |Index of the request parameter value.|
+| data | Uint8Array | Yes |Buffer for writing or reading data. |
## USBPort9+
@@ -738,11 +745,11 @@ Represents a USB port.
**System capability**: SystemCapability.USB.USBManager
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| id | number | Yes | Unique identifier of a USB port. |
-| supportedModes | [PortModeType](#portmodetype9) | Yes | Numeric mask combination for the supported mode list.|
-| status | [USBPortStatus](#usbportstatus9) | Yes | USB port role. |
+| Name | Type | Mandatory|Description |
+| -------------- | -------------------------------- | -------------- |----------------------------------- |
+| id | number | Yes |Unique identifier of a USB port. |
+| supportedModes | [PortModeType](#portmodetype9) | Yes |Numeric mask combination for the supported mode list.|
+| status | [USBPortStatus](#usbportstatus9) | Yes |USB port role. |
## USBPortStatus9+
@@ -752,11 +759,11 @@ Enumerates USB port roles.
**System capability**: SystemCapability.USB.USBManager
-| Name | Type | Mandatory | Description |
-| -------- | ------- | --------- | ----------- |
-| currentMode | number | Yes | Current USB mode. |
-| currentPowerRole | number | Yes | Current power role. |
-| currentDataRole | number | Yes | Current data role. |
+| Name | Type| Mandatory|Description |
+| ---------------- | -------- | ----------- |---------------------- |
+| currentMode | number | Yes |Current USB mode. |
+| currentPowerRole | number | Yes |Current power role. |
+| currentDataRole | number | Yes |Current data role.|
## USBRequestTargetType
@@ -841,7 +848,7 @@ Enumerates power role types.
| Name | Value | Description |
| ------ | ---- | ---------- |
-| NONE | 0 | None. |
+| NONE | 0 | None |
| SOURCE | 1 | External power supply.|
| SINK | 2 | Internal power supply.|
@@ -855,6 +862,6 @@ Enumerates data role types.
| Name | Value | Description |
| ------ | ---- | ------------ |
-| NONE | 0 | None. |
+| NONE | 0 | None |
| HOST | 1 | USB host.|
| DEVICE | 2 | USB device.|
diff --git a/en/application-dev/reference/apis/js-apis-usb.md b/en/application-dev/reference/apis/js-apis-usb.md
index 521fef517823a160e22a17b752fdc62443eeba7a..49bb9b53a08027852baa2614975e6ec9f53d90e9 100644
--- a/en/application-dev/reference/apis/js-apis-usb.md
+++ b/en/application-dev/reference/apis/js-apis-usb.md
@@ -1,9 +1,12 @@
-# @ohos.usbV9 (USB Management)
+# @ohos.usbV9 (USB)
The **usb** module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control on the host side as well as port management, and function switch and query on the device side.
-> **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.
+>
+> The APIs provided by this module are no longer maintained since API version 9. You are advised to use [`@ohos.usbManager`](js-apis-usbManager.md).
## Modules to Import
@@ -29,7 +32,7 @@ Obtains the list of USB devices connected to the host. If no device is connected
```js
let devicesList = usb.getDevices();
-console.log(`devicesList = ${JSON.stringify(devicesList)}`);
+console.log(`devicesList = ${devicesList}`);
// devicesList is a list of USB devices.
// A simple example of devicesList is provided as follows:
[
@@ -86,7 +89,7 @@ console.log(`devicesList = ${JSON.stringify(devicesList)}`);
connectDevice(device: USBDevice): Readonly<USBDevicePipe>
-Connects to a USB device based on the device list obtained by using **getDevices()**.
+Connects to the USB device based on the device information returned by **getDevices()**.
Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB device list and device information, and then call [usb.requestRight](#usbrequestright) to request the device access permission.
@@ -118,13 +121,12 @@ For details about the error codes, see [USB Error Codes](../errorcodes/errorcode
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
- return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
-console.log(`devicepipe = ${JSON.stringify(devicepipe)}`);
+console.log(`devicepipe = ${devicepipe}`);
```
## usb.hasRight
@@ -133,7 +135,7 @@ hasRight(deviceName: string): boolean
Checks whether the application has the permission to access the device.
-The value **true** is returned if the device access permission is available; the value **false** is returned otherwise.
+Checks whether the user, for example, the application or system, has the device access permissions. The value **true** is returned if the user has the device access permissions; the value **false** is returned otherwise.
**System capability**: SystemCapability.USB.USBManager
@@ -182,7 +184,7 @@ Requests the temporary permission for the application to access a USB device. Th
```js
let devicesName="1-1";
usb.requestRight(devicesName).then((ret) => {
- console.log(`requestRight = ${JSON.stringify(ret)}`);
+ console.log(`requestRight = ${ret}`);
});
```
@@ -210,7 +212,7 @@ Removes the permission for the application to access a USB device.
```js
let devicesName="1-1";
-if (usb.removeRight(devicesName) {
+if usb.removeRight(devicesName) {
console.log(`Succeed in removing right`);
}
```
@@ -245,7 +247,7 @@ Adds the permission for the application to access a USB device.
```js
let devicesName = "1-1";
let bundleName = "com.example.hello";
-if (usb.addRight(bundleName, devicesName) {
+if usb.addRight(bundleName, devicesName) {
console.log(`Succeed in adding right`);
}
```
@@ -454,8 +456,9 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
-usb.controlTransfer(devicepipe, USBControlParams).then((ret) => {
- console.log(`controlTransfer = ${JSON.stringify(ret)}`);
+let param = new usb.USBControlParams();
+usb.controlTransfer(devicepipe, param).then((ret) => {
+ console.log(`controlTransfer = ${ret}`);
})
```
@@ -491,7 +494,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
- console.log(`bulkTransfer = ${JSON.stringify(ret)}`);
+ console.log(`bulkTransfer = ${ret}`);
});
```
@@ -578,7 +581,7 @@ Converts the USB function list in the numeric mask format to a string in Device
**Example**
```js
-let funcs = ACM | ECM;
+let funcs = usb.ACM | usb.ECM;
let ret = usb.usbFunctionsToString(funcs);
```
@@ -600,14 +603,14 @@ Sets the current USB function list in Device mode.
**Return value**
-| Type | Description |
-| ------------------ | ------------------------------------------------------------ |
+| Type | Description |
+| --------------- | ------------- |
| Promise\ | Promise used to return the result.|
**Example**
```js
-let funcs = HDC;
+let funcs = usb.HDC;
usb.setCurrentFunctions(funcs).then(() => {
console.info('usb setCurrentFunctions successfully.');
}).catch(err => {
@@ -707,15 +710,15 @@ Sets the role types supported by a specified port, which can be **powerRole** (f
**Return value**
-| Type | Description |
-| ------------------ | ------------------------------------------------------------ |
-| Promise\ | Promise used to return the result. |
+| Type | Description |
+| --------------- | ------------- |
+| Promise\ | Promise used to return the result.|
**Example**
```js
let portId = 1;
-usb.usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
+usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
console.info('usb setPortRoles successfully.');
}).catch(err => {
console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
@@ -730,14 +733,14 @@ Represents the USB endpoint from which data is sent or received. You can obtain
| Name | Type | Mandatory |Description |
| ------------- | ------------------------------------------- | ------------- |------------- |
-| address | number | Yes | Endpoint address. |
-| attributes | number | Yes | Endpoint attributes. |
-| interval | number | Yes | Endpoint interval. |
-| maxPacketSize | number | Yes | Maximum size of data packets on the endpoint. |
-| direction | [USBRequestDirection](#usbrequestdirection) | Yes | Endpoint direction. |
-| number | number | Yes | Endpoint number. |
-| type | number | Yes | Endpoint type. |
-| interfaceId | number | Yes | Unique ID of the interface to which the endpoint belongs.|
+| address | number | Yes|Endpoint address. |
+| attributes | number | Yes|Endpoint attributes. |
+| interval | number | Yes|Endpoint interval. |
+| maxPacketSize | number | Yes|Maximum size of data packets on the endpoint. |
+| direction | [USBRequestDirection](#usbrequestdirection) | Yes|Endpoint direction. |
+| number | number | Yes|Endpoint number. |
+| type | number | Yes|Endpoint type. |
+| interfaceId | number | Yes|Unique ID of the interface to which the endpoint belongs.|
## USBInterface
@@ -747,13 +750,13 @@ Represents a USB interface. One [USBConfig](#usbconfig) can contain multiple **U
| Name | Type | Mandatory |Description |
| ---------------- | ---------------------------------------- | ------------- |--------------------- |
-| id | number | Yes | Unique ID of the USB interface. |
-| protocol | number | Yes | Interface protocol. |
-| clazz | number | Yes | Device type. |
-| subClass | number | Yes | Device subclass. |
-| alternateSetting | number | Yes | Settings for alternating between descriptors of the same USB interface.|
-| name | string | Yes | Interface name. |
-| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes | Endpoints that belong to the USB interface. |
+| id | number | Yes|Unique ID of the USB interface. |
+| protocol | number | Yes|Interface protocol. |
+| clazz | number | Yes|Device type. |
+| subClass | number | Yes|Device subclass. |
+| alternateSetting | number | Yes|Settings for alternating between descriptors of the same USB interface.|
+| name | string | Yes|Interface name. |
+| endpoints | Array<[USBEndpoint](#usbendpoint)> | Yes|Endpoints that belong to the USB interface. |
## USBConfig
@@ -763,13 +766,13 @@ Represents the USB configuration. One [USBDevice](#usbdevice) can contain multip
| Name | Type | Mandatory |Description |
| -------------- | ------------------------------------------------ | --------------- |--------------- |
-| id | number | Yes | Unique ID of the USB configuration. |
-| attributes | number | Yes | Configuration attributes. |
-| maxPower | number | Yes | Maximum power consumption, in mA. |
-| name | string | Yes | Configuration name, which can be left empty. |
-| isRemoteWakeup | boolean | Yes | Support for remote wakeup.|
-| isSelfPowered | boolean | Yes | Support for independent power supplies.|
-| interfaces | Array <[USBInterface](#usbinterface)> | Yes | Supported interface attributes. |
+| id | number | Yes|Unique ID of the USB configuration. |
+| attributes | number | Yes|Configuration attributes. |
+| maxPower | number | Yes|Maximum power consumption, in mA. |
+| name | string | Yes|Configuration name, which can be left empty. |
+| isRemoteWakeup | boolean | Yes|Support for remote wakeup.|
+| isSelfPowered | boolean | Yes| Support for independent power supplies.|
+| interfaces | Array <[USBInterface](#usbinterface)> | Yes|Supported interface attributes. |
## USBDevice
@@ -779,19 +782,19 @@ Represents the USB device information.
| Name | Type | Mandatory |Description |
| ---------------- | ------------------------------------ | ---------- |---------- |
-| busNum | number | Yes | Bus address. |
-| devAddress | number | Yes | Device address. |
-| serial | string | Yes | Sequence number. |
-| name | string | Yes | Device name. |
-| manufacturerName | string | Yes | Device manufacturer. |
-| productName | string | Yes | Product name. |
-| version | string | Yes | Version number. |
-| vendorId | number | Yes | Vendor ID. |
-| productId | number | Yes | Product ID. |
-| clazz | number | Yes | Device class. |
-| subClass | number | Yes | Device subclass. |
-| protocol | number | Yes | Device protocol code. |
-| configs | Array<[USBConfig](#usbconfig)> | Yes | Device configuration descriptor information.|
+| busNum | number | Yes|Bus address. |
+| devAddress | number | Yes|Device address. |
+| serial | string | Yes|Sequence number. |
+| name | string | Yes|Device name. |
+| manufacturerName | string | Yes| Device manufacturer. |
+| productName | string | Yes|Product name. |
+| version | string | Yes|Version number. |
+| vendorId | number | Yes|Vendor ID. |
+| productId | number | Yes|Product ID. |
+| clazz | number | Yes|Device class. |
+| subClass | number | Yes|Device subclass. |
+| protocol | number | Yes|Device protocol code. |
+| configs | Array<[USBConfig](#usbconfig)> | Yes|Device configuration descriptor information.|
## USBDevicePipe
@@ -812,12 +815,12 @@ Represents control transfer parameters.
| Name | Type | Mandatory |Description |
| ------- | ----------------------------------------------- | ---------------- |---------------- |
-| request | number | Yes | Request type. |
-| target | [USBRequestTargetType](#usbrequesttargettype) | Yes | Request target type. |
-| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes | Control request type. |
-| value | number | Yes | Request parameter value. |
-| index | number | Yes | Index of the request parameter value.|
-| data | Uint8Array | Yes | Buffer for writing or reading data. |
+| request | number | Yes |Request type. |
+| target | [USBRequestTargetType](#usbrequesttargettype) | Yes |Request target type. |
+| reqType | [USBControlRequestType](#usbcontrolrequesttype) | Yes |Control request type. |
+| value | number | Yes |Request parameter value. |
+| index | number | Yes |Index of the request parameter value.|
+| data | Uint8Array | Yes |Buffer for writing or reading data. |
## USBPort
@@ -829,9 +832,9 @@ Represents a USB port.
| Name | Type | Mandatory |Description |
| -------------- | ------------------------------- | ------------------- |------------------------ |
-| id | number | Yes | Unique identifier of a USB port. |
-| supportedModes | [PortModeType](#portmodetype) | Yes | Numeric mask combination for the supported mode list.|
-| status | [USBPortStatus](#usbportstatus) | Yes | USB port role. |
+| id | number | Yes |Unique identifier of a USB port. |
+| supportedModes | [PortModeType](#portmodetype) | Yes |Numeric mask combination for the supported mode list.|
+| status | [USBPortStatus](#usbportstatus) | Yes |USB port role. |
## USBPortStatus
@@ -843,9 +846,9 @@ Enumerates USB port roles.
| Name | Type| Mandatory |Description |
| ---------------- | -------- | ---------------- |---------------------- |
-| currentMode | number | Yes | Current USB mode. |
-| currentPowerRole | number | Yes | Current power role. |
-| currentDataRole | number | Yes | Current data role.|
+| currentMode | number | Yes|Current USB mode. |
+| currentPowerRole | number | Yes |Current power role. |
+| currentDataRole | number | Yes |Current data role.|
## USBRequestTargetType
@@ -853,12 +856,12 @@ Enumerates request target types.
**System capability**: SystemCapability.USB.USBManager
-| Name | Value | Description |
-| ---------------------------- | ----- | ----------- |
-| USB_REQUEST_TARGET_DEVICE | 0 | Device |
-| USB_REQUEST_TARGET_INTERFACE | 1 | Interface |
-| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint |
-| USB_REQUEST_TARGET_OTHER | 3 | Other |
+| Name | Value | Description |
+| ---------------------------- | ---- | ------ |
+| USB_REQUEST_TARGET_DEVICE | 0 | Device|
+| USB_REQUEST_TARGET_INTERFACE | 1 | Interface|
+| USB_REQUEST_TARGET_ENDPOINT | 2 | Endpoint|
+| USB_REQUEST_TARGET_OTHER | 3 | Other|
## USBControlRequestType
diff --git a/en/application-dev/reference/apis/js-apis-usbManager.md b/en/application-dev/reference/apis/js-apis-usbManager.md
index c75ebdeb327ca53b0d355515937046ab897a22fc..211a623cce941537d2d24f8ee3764608721bf6fe 100644
--- a/en/application-dev/reference/apis/js-apis-usbManager.md
+++ b/en/application-dev/reference/apis/js-apis-usbManager.md
@@ -1,4 +1,4 @@
-# @ohos.usbManager (USB Management)
+# @ohos.usbManager (USB Manager)
The **usbManager** module provides USB device management functions, including USB device list query, bulk data transfer, control transfer, and permission control on the host side as well as port management, and function switch and query on the device side.
@@ -30,7 +30,7 @@ Obtains the list of USB devices connected to the host. If no device is connected
```js
let devicesList = usb.getDevices();
-console.log(`devicesList = ${JSON.stringify(devicesList)}`);
+console.log(`devicesList = ${devicesList}`);
// devicesList is a list of USB devices.
// A simple example of devicesList is provided as follows:
[
@@ -119,13 +119,12 @@ For details about the error codes, see [USB Error Codes](../errorcodes/errorcode
let devicesList = usb.getDevices();
if (devicesList.length == 0) {
console.log(`device list is empty`);
- return;
}
let device = devicesList[0];
usb.requestRight(device.name);
let devicepipe = usb.connectDevice(device);
-console.log(`devicepipe = ${JSON.stringify(devicepipe)}`);
+console.log(`devicepipe = ${devicepipe}`);
```
## usb.hasRight
@@ -155,7 +154,7 @@ Checks whether the user, for example, the application or system, has the device
```js
let devicesName="1-1";
let bool = usb.hasRight(devicesName);
-console.log(bool);
+console.log(`${bool}`);
```
## usb.requestRight
@@ -183,7 +182,7 @@ Requests the temporary permission for the application to access a USB device. Th
```js
let devicesName="1-1";
usb.requestRight(devicesName).then((ret) => {
- console.log(`requestRight = ${JSON.stringify(ret)}`);
+ console.log(`requestRight = ${ret}`);
});
```
@@ -211,7 +210,7 @@ Removes the permission for the application to access a USB device.
```js
let devicesName="1-1";
-if (usb.removeRight(devicesName) {
+if usb.removeRight(devicesName) {
console.log(`Succeed in removing right`);
}
```
@@ -246,7 +245,7 @@ Adds the permission for the application to access a USB device.
```js
let devicesName = "1-1";
let bundleName = "com.example.hello";
-if (usb.addRight(bundleName, devicesName) {
+if usb.addRight(bundleName, devicesName) {
console.log(`Succeed in adding right`);
}
```
@@ -455,8 +454,9 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
**Example**
```js
-usb.controlTransfer(devicepipe, USBControlParams).then((ret) => {
- console.log(`controlTransfer = ${JSON.stringify(ret)}`);
+let param = new usb.USBControlParams();
+usb.controlTransfer(devicepipe, param).then((ret) => {
+ console.log(`controlTransfer = ${ret}`);
})
```
@@ -492,7 +492,7 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi
// Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device.
// Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer.
usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => {
- console.log(`bulkTransfer = ${JSON.stringify(ret)}`);
+ console.log(`bulkTransfer = ${ret}`);
});
```
@@ -579,7 +579,7 @@ Converts the USB function list in the numeric mask format to a string in Device
**Example**
```js
-let funcs = ACM | ECM;
+let funcs = usb.ACM | usb.ECM;
let ret = usb.usbFunctionsToString(funcs);
```
@@ -608,7 +608,7 @@ Sets the current USB function list in Device mode.
**Example**
```js
-let funcs = HDC;
+let funcs = usb.HDC;
usb.setCurrentFunctions(funcs).then(() => {
console.info('usb setCurrentFunctions successfully.');
}).catch(err => {
@@ -716,7 +716,7 @@ Sets the role types supported by a specified port, which can be **powerRole** (f
```js
let portId = 1;
-usb.usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
+usb.setPortRoles(portId, usb.PowerRoleType.SOURCE, usb.DataRoleType.HOST).then(() => {
console.info('usb setPortRoles successfully.');
}).catch(err => {
console.error('usb setPortRoles failed: ' + err.code + ' message: ' + err.message);
diff --git a/en/application-dev/reference/apis/js-apis-webSocket.md b/en/application-dev/reference/apis/js-apis-webSocket.md
index 6319fda995850708da44bec6c7d00dc158193516..bd7a55c09324684d80e787174483fcc8aefd884e 100644
--- a/en/application-dev/reference/apis/js-apis-webSocket.md
+++ b/en/application-dev/reference/apis/js-apis-webSocket.md
@@ -64,7 +64,7 @@ ws.connect(defaultIpAddress, (err, value) => {
## webSocket.createWebSocket
-createWebSocket\(\): WebSocket
+createWebSocket(): WebSocket
Creates a WebSocket connection. You can use this API to create or close a WebSocket connection, send data over it, or enable or disable listening for the **open**, **close**, **message**, and **error** events.
@@ -89,7 +89,7 @@ Defines a **WebSocket** object. Before invoking WebSocket APIs, you need to call
### connect
-connect\(url: string, callback: AsyncCallback\): void
+connect(url: string, callback: AsyncCallback\): void
Initiates a WebSocket request to establish a WebSocket connection to a given URL. This API uses an asynchronous callback to return the result.
@@ -128,7 +128,7 @@ ws.connect(url, (err, value) => {
### connect
-connect\(url: string, options: WebSocketRequestOptions, callback: AsyncCallback\): void
+connect(url: string, options: WebSocketRequestOptions, callback: AsyncCallback\): void
Initiates a WebSocket request carrying specified options to establish a WebSocket connection to a given URL. This API uses an asynchronous callback to return the result.
@@ -173,7 +173,7 @@ ws.connect(url, {
### connect
-connect\(url: string, options?: WebSocketRequestOptions\): Promise
+connect(url: string, options?: WebSocketRequestOptions): Promise\
Initiates a WebSocket request carrying specified options to establish a WebSocket connection to a given URL. This API uses a promise to return the result.
@@ -217,7 +217,7 @@ promise.then((value) => {
### send
-send\(data: string | ArrayBuffer, callback: AsyncCallback\): void
+send(data: string | ArrayBuffer, callback: AsyncCallback\): void
Sends data through a WebSocket connection. This API uses an asynchronous callback to return the result.
@@ -229,7 +229,7 @@ Sends data through a WebSocket connection. This API uses an asynchronous callbac
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------ |
-| data | string \| ArrayBuffer 8+ | Yes | Data to send.|
+| data | string \| ArrayBuffer | Yes | Data to send. Only the string type is supported for API version 6 or earlier. Both the string and ArrayBuffer types are supported for API version 8 or later.|
| callback | AsyncCallback\ | Yes | Callback used to return the result. |
**Error codes**
@@ -258,7 +258,7 @@ ws.connect(url, (err, value) => {
### send
-send\(data: string | ArrayBuffer\): Promise
+send(data: string | ArrayBuffer): Promise\
Sends data through a WebSocket connection. This API uses a promise to return the result.
@@ -270,7 +270,7 @@ Sends data through a WebSocket connection. This API uses a promise to return the
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------ |
-| data | string \| ArrayBuffer 8+ | Yes | Data to send.|
+| data | string \| ArrayBuffer | Yes | Data to send. Only the string type is supported for API version 6 or earlier. Both the string and ArrayBuffer types are supported for API version 8 or later.|
**Return value**
@@ -303,7 +303,7 @@ ws.connect(url, (err, value) => {
### close
-close\(callback: AsyncCallback\): void
+close(callback: AsyncCallback\): void
Closes a WebSocket connection. This API uses an asynchronous callback to return the result.
@@ -341,7 +341,7 @@ ws.close((err, value) => {
### close
-close\(options: WebSocketCloseOptions, callback: AsyncCallback\): void
+close(options: WebSocketCloseOptions, callback: AsyncCallback\): void
Closes a WebSocket connection carrying specified options such as **code** and **reason**. This API uses an asynchronous callback to return the result.
@@ -383,7 +383,7 @@ ws.close({
### close
-close\(options?: WebSocketCloseOptions\): Promise
+close(options?: WebSocketCloseOptions): Promise\
Closes a WebSocket connection carrying specified options such as **code** and **reason**. This API uses a promise to return the result.
@@ -427,9 +427,9 @@ promise.then((value) => {
```
-### on\('open'\)
+### on('open')
-on\(type: 'open', callback: AsyncCallback