提交 06a3c7ac 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 7df59f38
......@@ -53,7 +53,7 @@ Defines a reverse geocoding request.
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| latitude | number | Yes| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
## GeoCodeRequest
......@@ -66,7 +66,7 @@ Defines a geocoding request.
| -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| description | string | Yes| Yes| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
| minLatitude | number | Yes| Yes| Minimum latitude. This parameter is used with **minLongitude**, **maxLatitude**, and **maxLongitude** to specify the latitude and longitude ranges. The value ranges from **-90** to **90**.|
| minLongitude | number | Yes| Yes| Minimum longitude. The value ranges from **-180** to **180**.|
| maxLatitude | number | Yes| Yes| Maximum latitude. The value ranges from **-90** to **90**.|
......@@ -98,7 +98,7 @@ Defines a geographic location.
| phoneNumber | string | Yes| No| Phone number.|
| addressUrl | string | Yes| No| Website URL.|
| descriptions | Array&lt;string&gt; | Yes| No| Additional descriptions.|
| descriptionsSize | number | Yes| No| Total number of additional descriptions. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
| descriptionsSize | number | Yes| No| Total number of additional descriptions. The specified value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
| isFromMock | Boolean | Yes| No| Whether the geographical name is from the mock reverse geocoding function.<br>**System API**: This is a system API.|
......@@ -110,11 +110,11 @@ Defines a location request.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).|
| timeInterval | number | Yes| Yes| Time interval at which location information is reported, in seconds. The value must be greater than **0**.|
| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported. The value must be greater than **0**, in meters.|
| maxAccuracy | number | Yes| Yes| Location accuracy. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The value must be greater than **0**.|
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. This parameter is effective only when **scenario** is set to **UNSET**. If this parameter and **scenario** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. The **priority** parameter is effective only when this parameter is set to **UNSET**. If this parameter and **priority** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).|
| timeInterval | number | Yes| Yes| Time interval at which location information is reported, in seconds. The specified value must be greater than or equal to **0**. The default value is **1**.|
| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported, in meters. The specified value must be greater than or equal to **0**. The default value is **0**.|
| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The specified value must be greater than or equal to **0**. The default value is **0**.|
## CurrentLocationRequest
......@@ -125,10 +125,10 @@ Defines the current location request.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).|
| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The value must be greater than **0**.|
| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The value must be greater than or equal to **1000**.|
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request. This parameter is effective only when **scenario** is set to **UNSET**. If this parameter and **scenario** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestPriority](#locationrequestpriority).|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request. The **priority** parameter is effective only when this parameter is set to **UNSET**. If this parameter and **priority** are set to **UNSET**, the attempt to initiate a location request will fail. For details about the value range, see [LocationRequestScenario](#locationrequestscenario).|
| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The specified value must be greater than or equal to **0**. The default value is **0**.|
| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The specified value must be greater than or equal to **1000**.|
## SatelliteStatusInfo
......@@ -139,23 +139,23 @@ Defines the satellite status information.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| satellitesNumber | number | Yes| No| Number of satellites. The value must be greater than or equal to **0**.|
| satelliteIds | Array&lt;number&gt; | Yes| No| Array of satellite IDs. The value must be greater than or equal to **0**.|
| carrierToNoiseDensitys | Array&lt;number&gt; | Yes| No| Carrier-to-noise density ratio, that is, **cn0**. The value must be greater than **0**.|
| satellitesNumber | number | Yes| No| Number of satellites. The specified value must be greater than or equal to **0**.|
| satelliteIds | Array&lt;number&gt; | Yes| No| Array of satellite IDs. The specified value must be greater than or equal to **0**.|
| carrierToNoiseDensitys | Array&lt;number&gt; | Yes| No| Carrier-to-noise density ratio, that is, **cn0**. The specified value must be greater than **0**.|
| altitudes | Array&lt;number&gt; | Yes| No| Satellite altitude angle information. The value ranges from **-90** to **90**, in degrees.|
| azimuths | Array&lt;number&gt; | Yes| No| Azimuth information. The value ranges from **0** to **360**, in degrees.|
| carrierFrequencies | Array&lt;number&gt; | Yes| No| Carrier frequency. The value must be greater than or equal to **0**, in Hz.|
| carrierFrequencies | Array&lt;number&gt; | Yes| No| Carrier frequency, in Hz. The specified value must be greater than or equal to **0**.|
## CachedGnssLocationsRequest
Represents a request for reporting cached GNSS locations.
Defines a request for reporting cached GNSS locations.
**System capability**: SystemCapability.Location.Location.Gnss
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds. The value must be greater than **0**.|
| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds. The specified value must be greater than **0**.|
| wakeUpCacheQueueFull | boolean | Yes| Yes | **true**: reports the cached GNSS locations to the application when the cache queue is full.<br>**false**: discards the cached GNSS locations when the cache queue is full.|
......@@ -169,13 +169,13 @@ Defines a GNSS geofence. Currently, only circular geofences are supported.
| -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes| Yes|Latitude information. The value ranges from **-90** to **90**.|
| longitude | number | Yes|Yes| Longitude information. The value ranges from **-180** to **180**.|
| radius | number | Yes|Yes| Radius of a circular geofence. The value must be greater than **0**, in meters.|
| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds. The value must be greater than **0**.|
| radius | number | Yes|Yes| Radius of a circular geofence, in meters. The specified value must be greater than **0**.|
| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds. The specified value must be greater than **0**.|
## GeofenceRequest
Represents a GNSS geofencing request.
Defines a GNSS geofencing request.
**System capability**: SystemCapability.Location.Location.Geofence
......@@ -214,17 +214,17 @@ Defines a location.
| direction | number | Yes| No| Direction information. The value ranges from **0** to **360**, in degrees.|
| timeSinceBoot | number | Yes| No| Location timestamp since boot.|
| additions | Array&lt;string&gt; | Yes| No| Additional description.|
| additionSize | number | Yes| No| Number of additional descriptions. The value must be greater than or equal to **0**. |
| additionSize | number | Yes| No| Number of additional descriptions. The specified value must be greater than or equal to **0**. |
| isFromMock | Boolean | Yes| No| Whether the location information is from the mock location function.<br>**System API**: This is a system API.|
## ReverseGeocodingMockInfo
Represents information of the mock reverse geocoding function.
Defines the configuration of the mock reverse geocoding function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
......@@ -234,21 +234,21 @@ Represents information of the mock reverse geocoding function.
## LocationMockConfig
Represents the information of the mock location function.
Defines the configuration of the mock location function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| timeInterval | number | Yes| Yes| Interval at which mock locations are reported, in seconds.|
| timeInterval | number | Yes| Yes| Time interval at which mock locations are reported, in seconds.|
| locations | Array&lt;[Location](#location)&gt; | Yes| Yes| Array of mocked locations.|
## CountryCode
Represents country code information.
Defines the country code information.
**System capability**: SystemCapability.Location.Location.Core
......@@ -258,6 +258,69 @@ Represents country code information.
| type | [CountryCodeType](#countrycodetype) | Yes| No| Country code source.|
## LocatingRequiredDataConfig<sup>10+</sup>
Defines the configuration for obtaining the required data of the location service.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| type | [LocatingRequiredDataType](#locatingrequireddatatype10) | Yes| Yes| Type of the required data.|
| needStartScan | boolean | Yes| Yes| Whether to initiate scanning.|
| scanInterval | number | Yes| Yes| Scanning interval, in milliseconds. The specified value must be greater than **0**. The default value is **10000**.|
| scanTimeout | number | Yes| Yes| Scanning timeout interval, in milliseconds. The value ranges from **0** to **600000**. The default value is **10000**.|
## LocatingRequiredData<sup>10+</sup>
Defines the required data of the location service, including the Wi-Fi or Bluetooth scanning result. After obtaining the data, an application can use the data for services such as network positioning.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| wifiData | [WifiScanInfo](#wifiscaninfo10) | Yes| No| Wi-Fi scanning result.|
| bluetoothData | [BluetoothScanInfo](#bluetoothscaninfo10) | Yes| No| Bluetooth scanning result.|
## WifiScanInfo<sup>10+</sup>
Defines the Wi-Fi scanning information, including the SSID, BSSID, and RSSI of the scanned Wi-Fi hotspot.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| ssid | string | Yes| No| Service set identifier (SSID) of a Wi-Fi hotspot, in UTF-8 format.|
| bssid | string | Yes| No| Base station subsystem identifier (BSSID) of a Wi-Fi hotspot.|
| rssi | number | Yes| No| Received signal strength indicator (RSSI) of a Wi-Fi hotspot, in dBm.|
| frequency | number | Yes| No| Frequency of a Wi-Fi hotspot.|
| timestamp | number | Yes| No| Scanning timestamp.|
## BluetoothScanInfo<sup>10+</sup>
Defines the Bluetooth scanning information.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API.
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| deviceName | string | Yes| No| Name of a Bluetooth device.|
| macAddress | string | Yes| No| MAC address of a Bluetooth device.|
| rssi | number | Yes| No| Signal strength of a Bluetooth device, in dBm.|
| timestamp | number | Yes| No| Scanning timestamp.|
## LocationRequestPriority
Sets the priority of the location request.
......@@ -294,7 +357,7 @@ Defines the privacy statement type.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
| Name| Value| Description|
| -------- | -------- | -------- |
......@@ -305,7 +368,7 @@ Defines the privacy statement type.
## CountryCodeType
Represents the country code source type.
Defines the country code source type.
**System capability**: SystemCapability.Location.Location.Core
......@@ -317,11 +380,25 @@ Represents the country code source type.
| COUNTRY_CODE_FROM_NETWORK | 4 | Country code obtained from the cellular network registration information.|
## LocatingRequiredDataType<sup>10+</sup>
Defines the type of the required data of the location service.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API.
| Name| Value| Description|
| -------- | -------- | -------- |
| WIFI | 1 | Wi-Fi scanning information.|
| BLUETOOTH | 2 | Bluetooth scanning information.|
## geoLocationManager.on('locationChange')
on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;): void
Registers a listener for location changes with a location request initiated.
Subscribes to location change events with a location request initiated.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
......@@ -331,13 +408,13 @@ Registers a listener for location changes with a location request initiated.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
| type | string | Yes| Event type. The value **locationChange** indicates a location change.|
| request | [LocationRequest](#locationrequest) | Yes| Location request.|
| callback | Callback&lt;[Location](#location)&gt; | Yes| Callback used to return the location change event.|
| callback | Callback&lt;[Location](#location)&gt; | Yes| Callback used to receive location change events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -349,7 +426,7 @@ For details about the following error codes, see [Location Error Codes](../error
```ts
import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
};
......@@ -366,7 +443,7 @@ For details about the following error codes, see [Location Error Codes](../error
off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
Unregisters the listener for location changes with the corresponding location request deleted.
Unsubscribes from location change events with the corresponding location request deleted.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
......@@ -376,12 +453,12 @@ Unregisters the listener for location changes with the corresponding location re
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
| type | string | Yes| Event type. The value **locationChange** indicates a location change.|
| callback | Callback&lt;[Location](#location)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -393,7 +470,7 @@ For details about the following error codes, see [Location Error Codes](../error
```ts
import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
};
......@@ -410,7 +487,7 @@ For details about the following error codes, see [Location Error Codes](../error
on(type: 'locationEnabledChange', callback: Callback&lt;boolean&gt;): void
Registers a listener for location service status change events.
Subscribes to location service status change events.
**System capability**: SystemCapability.Location.Location.Core
......@@ -418,12 +495,12 @@ Registers a listener for location service status change events.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change event.|
| callback | Callback&lt;boolean&gt; | Yes| Callback used to return the location service status change event.|
| type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.|
| callback | Callback&lt;boolean&gt; | Yes| Callback used to receive location service status change events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -448,7 +525,7 @@ For details about the following error codes, see [Location Error Codes](../error
off(type: 'locationEnabledChange', callback?: Callback&lt;boolean&gt;): void;
Unregisters the listener for location service status change events.
Unsubscribes from location service status change events.
**System capability**: SystemCapability.Location.Location.Core
......@@ -456,12 +533,12 @@ Unregisters the listener for location service status change events.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change event.|
| type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change.|
| callback | Callback&lt;boolean&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -487,7 +564,7 @@ For details about the following error codes, see [Location Error Codes](../error
on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void;
Registers a listener for cached GNSS location reports.
Subscribes to cached GNSS location reports.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
......@@ -499,11 +576,11 @@ Registers a listener for cached GNSS location reports.
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.|
| request | [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | Yes| Request for reporting cached GNSS location.|
| callback | Callback&lt;boolean&gt; | Yes| Callback used to return cached GNSS locations.|
| callback | Callback&lt;boolean&gt; | Yes| Callback used to receive cached GNSS locations.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -531,7 +608,7 @@ For details about the following error codes, see [Location Error Codes](../error
off(type: 'cachedGnssLocationsChange', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void;
Unregisters the listener for cached GNSS location reports.
Unsubscribes from cached GNSS location reports.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
......@@ -546,7 +623,7 @@ Unregisters the listener for cached GNSS location reports.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -575,7 +652,7 @@ For details about the following error codes, see [Location Error Codes](../error
on(type: 'satelliteStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void;
Registers a listener for GNSS satellite status change events.
Subscribes to GNSS satellite status change events.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
......@@ -585,12 +662,12 @@ Registers a listener for GNSS satellite status change events.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change event.|
| callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | Yes| Callback used to return GNSS satellite status changes.|
| type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.|
| callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | Yes| Callback used to receive GNSS satellite status change events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -617,7 +694,7 @@ For details about the following error codes, see [Location Error Codes](../error
off(type: 'satelliteStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void;
Unregisters the listener for GNSS satellite status change events.
Unsubscribes from GNSS satellite status change events.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
......@@ -627,12 +704,12 @@ Unregisters the listener for GNSS satellite status change events.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change event.|
| type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change.|
| callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -660,7 +737,7 @@ For details about the following error codes, see [Location Error Codes](../error
on(type: 'nmeaMessage', callback: Callback&lt;string&gt;): void;
Registers a listener for GNSS NMEA message change events.
Subscribes to GNSS NMEA message change events.
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
......@@ -670,12 +747,12 @@ Registers a listener for GNSS NMEA message change events.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change event.|
| callback | Callback&lt;string&gt; | Yes| Callback used to return GNSS NMEA message changes.|
| type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.|
| callback | Callback&lt;string&gt; | Yes| Callback used to receive GNSS NMEA message change events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -703,7 +780,7 @@ For details about the following error codes, see [Location Error Codes](../error
off(type: 'nmeaMessage', callback?: Callback&lt;string&gt;): void;
Unregisters the listener for GNSS NMEA message change events.
Unsubscribes from GNSS NMEA message change events.
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
......@@ -713,12 +790,12 @@ Unregisters the listener for GNSS NMEA message change events.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change event.|
| type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change.|
| callback | Callback&lt;string&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -747,7 +824,7 @@ For details about the following error codes, see [Location Error Codes](../error
on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Registers a listener for status change events of the specified geofence.
Subscribes to status change events of the specified geofence.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
......@@ -757,13 +834,13 @@ Registers a listener for status change events of the specified geofence.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change event.|
| type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.|
| request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
| want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
| want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -805,7 +882,7 @@ For details about the following error codes, see [Location Error Codes](../error
off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Unregisters the listener for status change events of the specified geofence.
Unsubscribes from status change events of the specified geofence.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
......@@ -815,13 +892,13 @@ Unregisters the listener for status change events of the specified geofence.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change event.|
| type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change.|
| request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
| want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
| want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -864,7 +941,7 @@ For details about the following error codes, see [Location Error Codes](../error
on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;): void;
Registers a listener for country code change events.
Subscribes to country code change events.
**System capability**: SystemCapability.Location.Location.Core
......@@ -872,12 +949,12 @@ Registers a listener for country code change events.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change event.|
| callback | Callback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to return the country code change event.|
| type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.|
| callback | Callback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to receive country code change events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -905,7 +982,7 @@ For details about the following error codes, see [Location Error Codes](../error
off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;): void;
Unregisters the listener for country code change events.
Unsubscribes from country code change events.
**System capability**: SystemCapability.Location.Location.Core
......@@ -913,12 +990,12 @@ Unregisters the listener for country code change events.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change event.|
| type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change.|
| callback | Callback&lt;[CountryCode](#countrycode)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -942,6 +1019,89 @@ For details about the following error codes, see [Location Error Codes](../error
```
## geoLocationManager.on('locatingRequiredDataChange')<sup>10+</sup>
on(type: 'locatingRequiredDataChange', config: LocatingRequiredDataConfig, callback: Callback&lt;Array&lt;LocatingRequiredData&gt;&gt;): void;
Subscribes to changes in the required data of the location service, including Wi-Fi and Bluetooth scanning information. An application can then determine whether to enable Wi-Fi and Bluetooth scanning based on the return result.
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.|
| config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.|
| callback | Callback&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | Yes| Callback used to receive the required data of the location service.|
**Error codes**
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301800 | Failed to start WiFi or Bluetooth scanning. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
let callback = (code) => {
console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
}
let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
try {
geoLocationManager.on('locatingRequiredDataChange', config, callback);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.off('locatingRequiredDataChange')<sup>10+</sup>
off(type: 'locatingRequiredDataChange', callback?: Callback&lt;Array&lt;LocatingRequiredData&gt;&gt;): void;
Unsubscribes from changes in the required data of the location service and stops Wi-Fi and Bluetooth scanning.
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locatingRequiredDataChange** indicates a change in the required data of the location service.|
| callback | Callback&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
let callback = (code) => {
console.log('locatingRequiredDataChange: ' + JSON.stringify(code));
}
let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
try {
geoLocationManager.on('locatingRequiredDataChange', config, callback);
geoLocationManager.off('locatingRequiredDataChange', callback);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.getCurrentLocation
......@@ -958,11 +1118,11 @@ Obtains the current location. This API uses an asynchronous callback to return t
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.|
| callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|
| callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to receive the current location.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -974,7 +1134,7 @@ For details about the following error codes, see [Location Error Codes](../error
```ts
import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
let locationChange = (err, location) => {
if (err) {
console.log('locationChanger: err=' + JSON.stringify(err));
......@@ -1005,11 +1165,11 @@ Obtains the current location. This API uses an asynchronous callback to return t
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|
| callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to receive the current location.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1061,7 +1221,7 @@ Obtains the current location. This API uses a promise to return the result.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1073,7 +1233,7 @@ For details about the following error codes, see [Location Error Codes](../error
```ts
import geoLocationManager from '@ohos.geoLocationManager';
let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0};
try {
geoLocationManager.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result));
......@@ -1105,7 +1265,7 @@ Obtains the last location.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1141,7 +1301,7 @@ Checks whether the location service is enabled.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1165,7 +1325,7 @@ enableLocation(callback: AsyncCallback&lt;void&gt;): void;
Enables the location service. This API uses an asynchronous callback to return the result.
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
......@@ -1175,11 +1335,11 @@ Enables the location service. This API uses an asynchronous callback to return t
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error message.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error message.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1207,7 +1367,7 @@ enableLocation(): Promise&lt;void&gt;
Enables the location service. This API uses a promise to return the result.
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
......@@ -1221,7 +1381,7 @@ Enables the location service. This API uses a promise to return the result.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1249,7 +1409,7 @@ disableLocation(): void;
Disables the location service.
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
......@@ -1257,7 +1417,7 @@ Disables the location service.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1275,7 +1435,6 @@ For details about the following error codes, see [Location Error Codes](../error
```
## geoLocationManager.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
......@@ -1289,11 +1448,11 @@ Converts coordinates into geographic description through reverse geocoding. This
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the reverse geocoding result.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to receive the reverse geocoding result.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1342,7 +1501,7 @@ Converts coordinates into geographic description through reverse geocoding. This
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1380,11 +1539,11 @@ Converts geographic description into coordinates through geocoding. This API use
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the geocoding result.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to receive the geocoding result.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1433,7 +1592,7 @@ Converts geographic description into coordinates through geocoding. This API use
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1473,7 +1632,7 @@ Obtains the (reverse) geocoding service status.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1505,11 +1664,11 @@ Obtains the number of cached GNSS locations.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of cached GNSS locations. |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to receive the number of cached GNSS locations. |
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1553,7 +1712,7 @@ Obtains the number of cached GNSS locations.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1591,11 +1750,11 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error message.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error message.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1633,11 +1792,11 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | NA | Promise used to return the error code.|
| Promise&lt;void&gt; | void | NA | Promise used to receive the error code.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1675,11 +1834,11 @@ Sends an extended command to the location subsystem.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error code.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to receive the error code.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1720,11 +1879,11 @@ Sends an extended command to the location subsystem.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | NA | Promise used to return the error code.|
| Promise&lt;void&gt; | void | NA | Promise used to receive the error code.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1760,11 +1919,11 @@ Obtains the current country code.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to return the country code.|
| callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to receive the country code.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1802,11 +1961,11 @@ Obtains the current country code.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | NA | Promise used to return the country code.|
| Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | NA | Promise used to receive the country code.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1839,11 +1998,11 @@ Enables the mock location function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1870,11 +2029,11 @@ Disables the mock location function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1903,7 +2062,7 @@ This API can be invoked only after [geoLocationManager.enableLocationMock](#geol
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Parameters**
......@@ -1913,7 +2072,7 @@ This API can be invoked only after [geoLocationManager.enableLocationMock](#geol
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1949,11 +2108,11 @@ Enables the mock reverse geocoding function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -1979,11 +2138,11 @@ Disables the mock geocoding function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -2011,7 +2170,7 @@ This API can be invoked only after [geoLocationManager.enableReverseGeocodingMoc
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Parameters**
......@@ -2021,7 +2180,7 @@ This API can be invoked only after [geoLocationManager.enableReverseGeocodingMoc
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -2053,7 +2212,7 @@ isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean;
Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications.
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**System capability**: SystemCapability.Location.Location.Core
......@@ -2067,11 +2226,11 @@ Checks whether a user agrees with the privacy statement of the location service.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| boolean | boolean | NA | Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
| boolean | boolean | NA | Whether the user agrees with the privacy statement.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -2095,7 +2254,7 @@ setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean)
Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
**System API**: This is a system API and cannot be called by third-party applications.
**System API**: This is a system API.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
......@@ -2106,11 +2265,11 @@ Sets the user confirmation status for the privacy statement of the location serv
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype) | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled.|
| isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
| isConfirmed | boolean | Yes| Whether the user agrees with the privacy statement.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
......@@ -2126,3 +2285,53 @@ For details about the following error codes, see [Location Error Codes](../error
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.getLocatingRequiredData<sup>10+</sup>
getLocatingRequiredData(config: LocatingRequiredDataConfig): Promise&lt;Array&lt;LocatingRequiredData&gt;&gt;;
Obtains the required data of the location service. This API uses a promise to return the result.
**Required permissions**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | [LocatingRequiredDataConfig](#locatingrequireddataconfig10) | Yes| Configuration for obtaining the required data of the location service.|
**Return value**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Promise&lt;Array&lt;[LocatingRequiredData](#locatingrequireddata10)&gt;&gt; | [LocatingRequiredData](#locatingrequireddata10) | NA | Promise used to receive the required data of the location service, such as the Wi-Fi and Bluetooth scanning information.|
**Error codes**
For details about the error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301800 | Failed to start WiFi or Bluetooth scanning. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000};
try {
geoLocationManager.getLocatingRequiredData(config).then((result) => {
console.log('getLocatingRequiredData return: ' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, getLocatingRequiredData: error=' + JSON.stringify(error));
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
......@@ -175,23 +175,30 @@ Obtains system service information.
```js
import fs from '@ohos.file.fs'
import hidebug from '@ohos.hidebug'
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext();
context.getFilesDir().then((data) => {
var path = data + "/serviceInfo.txt";
console.info("output path: " + path);
let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
var serviceId = 10;
var args = new Array("allInfo");
try {
hidebug.getServiceDump(serviceId, file.fd, args);
} catch (error) {
console.info(error.code);
console.info(error.message);
}
fs.closeSync(file);
})
import common from '@ohos.app.ability.common'
let applicationContext: common.Context;
try {
applicationContext = this.context.getApplicationContext();
} catch (error) {
console.info(error.code);
console.info(error.message);
}
var filesDir = applicationContext.filesDir;
var path = filesDir + "/serviceInfo.txt";
console.info("output path: " + path);
let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
var serviceId = 10;
var args = new Array("allInfo");
try {
hidebug.getServiceDump(serviceId, file.fd, args);
} catch (error) {
console.info(error.code);
console.info(error.message);
}
fs.closeSync(file);
```
## hidebug.startJsCpuProfiling<sup>9+</sup>
......
......@@ -89,9 +89,11 @@ Specifies whether background applications are allowed to access the network. Thi
**Example**
```js
policy.setBackgroundAllowed(true).then(function (error) {
console.log(JSON.stringify(error))
})
policy.setBackgroundAllowed(true).then(() => {
console.log("setBackgroundAllowed success");
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.isBackgroundAllowed<sup>10+</sup>
......@@ -164,10 +166,11 @@ Checks whether the current application is allowed to access the network when run
**Example**
```js
policy.isBackgroundAllowed().then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.isBackgroundAllowed().then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.setPolicyByUid<sup>10+</sup>
......@@ -248,9 +251,11 @@ Sets the metered network access policy for the application specified by a given
**Example**
```js
policy.setPolicyByUid(11111, policy.NetUidPolicy.NET_POLICY_NONE).then(function (error) {
console.log(JSON.stringify(error))
})
policy.setPolicyByUid(11111, policy.NetUidPolicy.NET_POLICY_NONE).then(() => {
console.log("setPolicyByUid success");
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.getPolicyByUid<sup>10+</sup>
......@@ -329,10 +334,11 @@ Obtains the network access policy for the application specified by a given UID.
**Example**
```js
policy.getPolicyByUid(11111).then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.getPolicyByUid(11111).then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.getUidsByPolicy<sup>10+</sup>
......@@ -412,10 +418,11 @@ Obtains all UIDs that match the specified network policy. This API uses a promis
**Example**
```js
policy.getUidsByPolicy(11111).then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.getUidsByPolicy(11111).then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.getNetQuotaPolicies<sup>10+</sup>
......@@ -487,11 +494,11 @@ Obtains the network quota policies. This API uses a promise to return the result
**Example**
```js
policy.getNetQuotaPolicies().then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.getNetQuotaPolicies().then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.setNetQuotaPolicies<sup>10+</sup>
......@@ -608,9 +615,11 @@ let netquotapolicy = {
netQuotaPolicyList.push(netquotapolicy);
policy.setNetQuotaPolicies(netQuotaPolicyList).then(function (error) {
console.log(JSON.stringify(error))
})
policy.setNetQuotaPolicies(netQuotaPolicyList).then(() => {
console.log("setNetQuotaPolicies success");
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.isUidNetAllowed<sup>10+</sup>
......@@ -692,10 +701,11 @@ Checks whether the application specified by a given UID is allowed to access a m
**Example**
```js
policy.isUidNetAllowed(11111, true).then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.isUidNetAllowed(11111, true).then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.isUidNetAllowed<sup>10+</sup>
......@@ -777,10 +787,11 @@ Checks whether the application specified by a given UID is allowed to access the
**Example**
```js
policy.isUidNetAllowed(11111, 'wlan0').then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.isUidNetAllowed(11111, 'wlan0').then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.setDeviceIdleTrustlist<sup>10+</sup>
......@@ -861,9 +872,11 @@ Adds applications specified by given UIDs to the device idle allowlist. This API
**Example**
```js
policy.setDeviceIdleTrustlist([11111,22222], true).then(function (error) {
console.log(JSON.stringify(error))
})
policy.setDeviceIdleTrustlist([11111,22222], true).then(() => {
console.log("setDeviceIdleTrustlist success");
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.getDeviceIdleTrustlist<sup>10+</sup>
......@@ -934,10 +947,11 @@ Obtains the UIDs of applications that are on the device idle allowlist. This API
**Example**
```js
policy.getDeviceIdleTrustlist().then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.getDeviceIdleTrustlist().then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.getBackgroundPolicyByUid<sup>10+</sup>
......@@ -1017,10 +1031,11 @@ Obtains the background network policy for the application specified by a given U
**Example**
```js
policy.getBackgroundPolicyByUid(11111).then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.getBackgroundPolicyByUid(11111).then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.resetPolicies<sup>10+</sup>
......@@ -1099,9 +1114,11 @@ Restores all the policies (cellular network, background network, firewall, and a
**Example**
```js
policy.resetPolicies('1').then(function (error) {
console.log(JSON.stringify(error))
})
policy.resetPolicies('1').then(() => {
console.log("resetPolicies success");
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.updateRemindPolicy<sup>10+</sup>
......@@ -1186,9 +1203,11 @@ Updates a reminder policy. This API uses a promise to return the result.
```js
import connection from '@ohos.net.connection';
policy.updateRemindPolicy(connection.NetBearType.BEARER_CELLULAR, '1', policy.RemindType.REMIND_TYPE_WARNING).then(function (error) {
console.log(JSON.stringify(error))
})
policy.updateRemindPolicy(connection.NetBearType.BEARER_CELLULAR, '1', policy.RemindType.REMIND_TYPE_WARNING).then(() => {
console.log("updateRemindPolicy success");
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.setPowerSaveTrustlist<sup>10+</sup>
......@@ -1269,9 +1288,11 @@ Sets whether to add the application specified by a given UID to the power-saving
**Example**
```js
policy.setPowerSaveTrustlist([11111,22222], true).then(function (error) {
console.log(JSON.stringify(error))
})
policy.setPowerSaveTrustlist([11111,22222], true).then(() => {
console.log("setPowerSaveTrustlist success");
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.getPowerSaveTrustlist<sup>10+</sup>
......@@ -1343,10 +1364,11 @@ Obtains the UID array of applications that are on the device idle allowlist. Thi
**Example**
```js
policy.getPowerSaveTrustlist().then(function (error, data) {
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
policy.getPowerSaveTrustlist().then((data) => {
console.log(JSON.stringify(data));
}).catch(error => {
console.log(JSON.stringify(error));
});
```
## policy.on
......
# # @ohos.net.socket (Socket Connection)
The **socket** module implements data transfer over TCPSocket, UDPSocket, WebSocket, and TLSSocket connections.
The **socket** module implements data transfer over TCP, UDP, Web, and TLS socket connections.
> **NOTE**
>
......@@ -34,7 +34,7 @@ let udp = socket.constructUDPSocketInstance();
## UDPSocket<sup>7+</sup>
Defines a UDPSocket connection. Before calling UDPSocket APIs, you need to call [socket.constructUDPSocketInstance](#socketconstructudpsocketinstance) to create a **UDPSocket** object.
Defines a UDP socket connection. Before calling UDPSocket APIs, you need to call [socket.constructUDPSocketInstance](#socketconstructudpsocketinstance) to create a **UDPSocket** object.
### bind<sup>7+</sup>
......@@ -118,7 +118,7 @@ promise.then(() => {
send(options: UDPSendOptions, callback: AsyncCallback\<void\>): void
Sends data over a UDPSocket connection. This API uses an asynchronous callback to return the result.
Sends data over a UDP socket connection. This API uses an asynchronous callback to return the result.
Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port.
......@@ -130,7 +130,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDPSocket connection. For details, see [UDPSendOptions](#udpsendoptions).|
| options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDP socket connection. For details, see [UDPSendOptions](#udpsendoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
......@@ -164,7 +164,7 @@ udp.send({
send(options: UDPSendOptions): Promise\<void\>
Sends data over a UDPSocket connection. This API uses a promise to return the result.
Sends data over a UDP socket connection. This API uses a promise to return the result.
Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and port.
......@@ -176,7 +176,7 @@ Before sending data, call [UDPSocket.bind()](#bind) to bind the IP address and p
| Name | Type | Mandatory| Description |
| ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDPSocket connection. For details, see [UDPSendOptions](#udpsendoptions).|
| options | [UDPSendOptions](#udpsendoptions) | Yes | Parameters for sending data over the UDP socket connection. For details, see [UDPSendOptions](#udpsendoptions).|
**Error codes**
......@@ -214,7 +214,7 @@ promise.then(() => {
close(callback: AsyncCallback\<void\>): void
Closes a UDPSocket connection. This API uses an asynchronous callback to return the result.
Closes a UDP socket connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
......@@ -243,7 +243,7 @@ udp.close(err => {
close(): Promise\<void\>
Closes a UDPSocket connection. This API uses a promise to return the result.
Closes a UDP socket connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
......@@ -271,7 +271,7 @@ promise.then(() => {
getState(callback: AsyncCallback\<SocketStateBase\>): void
Obtains the status of the UDPSocket connection. This API uses an asynchronous callback to return the result.
Obtains the status of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **bind** is successfully called.
......@@ -316,7 +316,7 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
getState(): Promise\<SocketStateBase\>
Obtains the status of the UDPSocket connection. This API uses a promise to return the result.
Obtains the status of the UDP socket connection. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **bind** is successfully called.
......@@ -355,7 +355,7 @@ promise.then(err => {
setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the UDPSocket connection. This API uses an asynchronous callback to return the result.
Sets other properties of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **bind** is successfully called.
......@@ -368,7 +368,7 @@ Sets other properties of the UDPSocket connection. This API uses an asynchronous
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDPSocket connection. For details, see [UDPExtraOptions](#udpextraoptions).|
| options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDP socket connection. For details, see [UDPExtraOptions](#udpextraoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
......@@ -408,7 +408,7 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
setExtraOptions(options: UDPExtraOptions): Promise\<void\>
Sets other properties of the UDPSocket connection. This API uses a promise to return the result.
Sets other properties of the UDP socket connection. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **bind** is successfully called.
......@@ -421,7 +421,7 @@ Sets other properties of the UDPSocket connection. This API uses a promise to re
| Name | Type | Mandatory| Description |
| ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDPSocket connection. For details, see [UDPExtraOptions](#udpextraoptions).|
| options | [UDPExtraOptions](#udpextraoptions) | Yes | Other properties of the UDP socket connection. For details, see [UDPExtraOptions](#udpextraoptions).|
**Return value**
......@@ -464,7 +464,7 @@ promise.then(() => {
on(type: 'message', callback: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for message receiving events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to **message** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -495,10 +495,10 @@ udp.on('message', value => {
off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for message receiving events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **message** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -524,7 +524,7 @@ let callback = value => {
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
}
udp.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
udp.off('message', callback);
udp.off('message');
```
......@@ -533,7 +533,7 @@ udp.off('message');
on(type: 'listening' | 'close', callback: Callback\<void\>): void
Enables listening for data packet message events or close events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to **listening** events or **close** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -560,10 +560,10 @@ udp.on('close', () => {
off(type: 'listening' | 'close', callback?: Callback\<void\>): void
Disables listening for data packet message events or close events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **listening** events or **close** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -582,14 +582,14 @@ let callback1 = () => {
console.log("on listening, success");
}
udp.on('listening', callback1);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
udp.off('listening', callback1);
udp.off('listening');
let callback2 = () => {
console.log("on close, success");
}
udp.on('close', callback2);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
udp.off('close', callback2);
udp.off('close');
```
......@@ -598,7 +598,7 @@ udp.off('close');
on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to **error** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -622,10 +622,10 @@ udp.on('error', err => {
off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the UDPSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **error** events of the UDP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -644,7 +644,7 @@ let callback = err => {
console.log("on error, err:" + JSON.stringify(err));
}
udp.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
udp.off('error', callback);
udp.off('error');
```
......@@ -663,7 +663,7 @@ Defines the destination address.
## UDPSendOptions<sup>7+</sup>
Defines the parameters for sending data over the UDPSocket connection.
Defines the parameters for sending data over the UDP socket connection.
**System capability**: SystemCapability.Communication.NetStack
......@@ -674,7 +674,7 @@ Defines the parameters for sending data over the UDPSocket connection.
## UDPExtraOptions<sup>7+</sup>
Defines other properties of the UDPSocket connection.
Defines other properties of the UDP socket connection.
**System capability**: SystemCapability.Communication.NetStack
......@@ -684,7 +684,7 @@ Defines other properties of the UDPSocket connection.
| receiveBufferSize | number | No | Size of the receive buffer, in bytes. The default value is **0**. |
| sendBufferSize | number | No | Size of the send buffer, in bytes. The default value is **0**. |
| reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. |
| socketTimeout | number | No | Timeout duration of the UDPSocket connection, in ms. The default value is **0**.|
| socketTimeout | number | No | Timeout duration of the UDP socket connection, in ms. The default value is **0**.|
## SocketStateBase<sup>7+</sup>
......@@ -739,7 +739,7 @@ let tcp = socket.constructTCPSocketInstance();
## TCPSocket<sup>7+</sup>
Defines a TCPSocket connection. Before calling TCPSocket APIs, you need to call [socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance) to create a **TCPSocket** object.
Defines a TCP socket connection. Before calling TCPSocket APIs, you need to call [socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance) to create a **TCPSocket** object.
### bind<sup>7+</sup>
......@@ -747,6 +747,9 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): void
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. This API uses an asynchronous callback to return the result.
> **NOTE**
> If the operation fails, the system randomly allocates a port number.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
......@@ -784,6 +787,9 @@ bind(address: NetAddress): Promise\<void\>
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. This API uses a promise to return the result.
> **NOTE**
> If the operation fails, the system randomly allocates a port number.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
......@@ -836,7 +842,7 @@ Sets up a connection to the specified IP address and port number. This API uses
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCPSocket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).|
| options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCP socket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
......@@ -873,7 +879,7 @@ Sets up a connection to the specified IP address and port number. This API uses
| Name | Type | Mandatory| Description |
| ------- | ---------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCPSocket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).|
| options | [TCPConnectOptions](#tcpconnectoptions) | Yes | TCP socket connection parameters. For details, see [TCPConnectOptions](#tcpconnectoptions).|
**Return value**
......@@ -904,7 +910,7 @@ promise.then(() => {
send(options: TCPSendOptions, callback: AsyncCallback\<void\>): void
Sends data over a TCPSocket connection. This API uses an asynchronous callback to return the result.
Sends data over a TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **connect** is successfully called.
......@@ -917,7 +923,7 @@ Sends data over a TCPSocket connection. This API uses an asynchronous callback t
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCPSocket connection. For details, see [TCPSendOptions](#tcpsendoptions).|
| options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCP socket connection. For details, see [TCPSendOptions](#tcpsendoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
......@@ -950,7 +956,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim
send(options: TCPSendOptions): Promise\<void\>
Sends data over a TCPSocket connection. This API uses a promise to return the result.
Sends data over a TCP socket connection. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **connect** is successfully called.
......@@ -963,7 +969,7 @@ Sends data over a TCPSocket connection. This API uses a promise to return the re
| Name | Type | Mandatory| Description |
| ------- | --------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCPSocket connection. For details, see [TCPSendOptions](#tcpsendoptions).|
| options | [TCPSendOptions](#tcpsendoptions) | Yes | Parameters for sending data over the TCP socket connection. For details, see [TCPSendOptions](#tcpsendoptions).|
**Return value**
......@@ -1002,7 +1008,7 @@ promise1.then(() => {
close(callback: AsyncCallback\<void\>): void
Closes a TCPSocket connection. This API uses an asynchronous callback to return the result.
Closes a TCP socket connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
......@@ -1037,7 +1043,7 @@ tcp.close(err => {
close(): Promise\<void\>
Closes a TCPSocket connection. This API uses a promise to return the result.
Closes a TCP socket connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
......@@ -1155,7 +1161,7 @@ promise1.then(() => {
getState(callback: AsyncCallback\<SocketStateBase\>): void
Obtains the status of the TCPSocket connection. This API uses an asynchronous callback to return the result.
Obtains the status of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **bind** or **connect** is successfully called.
......@@ -1196,7 +1202,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa
getState(): Promise\<SocketStateBase\>
Obtains the status of the TCPSocket connection. This API uses a promise to return the result.
Obtains the status of the TCP socket connection. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **bind** or **connect** is successfully called.
......@@ -1235,11 +1241,92 @@ promise.then(() => {
});
```
### getSocketFd<sup>10+</sup>
getSocketFd(callback: AsyncCallback\<number\>): void
Obtains the file descriptor of the **TCPSocket** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **bind** or **connect** is successfully called.
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------ | ---- | ---------- |
| callback | AsyncCallback\<number\> | Yes | Callback used to return the result. If the operation is successful, the file descriptor of the socket is returned. Otherwise, **undefined** is returned.|
**Example**
```js
import socket from "@ohos.net.socket";
var tcp = socket.constructTCPSocketInstance();
let tunnelfd = 0
tcp.bind({
address: "0.0.0.0",
family: 1,
})
let connectAddress = {
address: "192.168.1.11",
port: 8888,
family: 1
};
tcp.connect({
address: connectAddress, timeout: 6000
})
tcp.getSocketFd((data) => {
console.info("tunenlfd: " + data);
tunnelfd = data
})
```
### getSocketFd<sup>10+</sup>
getSocketFd(): Promise\<number\>
Obtains the file descriptor of the **TCPSocket** object. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **bind** or **connect** is successfully called.
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| :----------------------------------------------- | :----------------------------------------- |
| Promise\<number\> | Promise used to return the result.|
**Example**
```js
import socket from "@ohos.net.socket";
var tcp = socket.constructTCPSocketInstance();
let tunnelfd = 0
tcp.bind({
address: "0.0.0.0",
family: 1,
})
let connectAddress = {
address: "192.168.1.11",
port: 8888,
family: 1
};
tcp.connect({
address: connectAddress, timeout: 6000
})
tcp.getSocketFd().then((data) => {
console.info("tunenlfd: " + data);
tunnelfd = data
})
```
### setExtraOptions<sup>7+</sup>
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the TCPSocket connection. This API uses an asynchronous callback to return the result.
Sets other properties of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **bind** or **connect** is successfully called.
......@@ -1252,7 +1339,7 @@ Sets other properties of the TCPSocket connection. This API uses an asynchronous
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. |
**Error codes**
......@@ -1291,7 +1378,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa
setExtraOptions(options: TCPExtraOptions): Promise\<void\>
Sets other properties of the TCPSocket connection. This API uses a promise to return the result.
Sets other properties of the TCP socket connection. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **bind** or **connect** is successfully called.
......@@ -1304,7 +1391,7 @@ Sets other properties of the TCPSocket connection. This API uses a promise to re
| Name | Type | Mandatory| Description |
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
**Return value**
......@@ -1350,7 +1437,7 @@ promise.then(() => {
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for message receiving events of the TCPSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to **message** events of the TCP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1381,10 +1468,10 @@ tcp.on('message', value => {
off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for message receiving events of the TCPSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **message** events of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1410,7 +1497,7 @@ let callback = value => {
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
}
tcp.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcp.off('message', callback);
tcp.off('message');
```
......@@ -1419,7 +1506,7 @@ tcp.off('message');
on(type: 'connect' | 'close', callback: Callback\<void\>): void
Enables listening for connection or close events of the TCPSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to connection or close events of the TCP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1446,10 +1533,10 @@ tcp.on('close', () => {
off(type: 'connect' | 'close', callback?: Callback\<void\>): void
Disables listening for connection or close events of the TCPSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from connection or close events of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1468,14 +1555,14 @@ let callback1 = () => {
console.log("on connect success");
}
tcp.on('connect', callback1);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcp.off('connect', callback1);
tcp.off('connect');
let callback2 = () => {
console.log("on close success");
}
tcp.on('close', callback2);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcp.off('close', callback2);
tcp.off('close');
```
......@@ -1484,7 +1571,7 @@ tcp.off('close');
on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the TCPSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to **error** events of the TCP socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1508,10 +1595,10 @@ tcp.on('error', err => {
off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the TCPSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **error** events of the TCP socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1530,25 +1617,25 @@ let callback = err => {
console.log("on error, err:" + JSON.stringify(err));
}
tcp.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcp.off('error', callback);
tcp.off('error');
```
## TCPConnectOptions<sup>7+</sup>
Defines TCPSocket connection parameters.
Defines TCP socket connection parameters.
**System capability**: SystemCapability.Communication.NetStack
| Name | Type | Mandatory| Description |
| ------- | ---------------------------------- | ---- | -------------------------- |
| address | [NetAddress](#netaddress) | Yes | Bound IP address and port number. |
| timeout | number | No | Timeout duration of the TCPSocket connection, in ms.|
| timeout | number | No | Timeout duration of the TCP socket connection, in ms.|
## TCPSendOptions<sup>7+</sup>
Defines the parameters for sending data over the TCPSocket connection.
Defines the parameters for sending data over the TCP socket connection.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1559,7 +1646,7 @@ Defines the parameters for sending data over the TCPSocket connection.
## TCPExtraOptions<sup>7+</sup>
Defines other properties of the TCPSocket connection.
Defines other properties of the TCP socket connection.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1567,12 +1654,12 @@ Defines other properties of the TCPSocket connection.
| ----------------- | ------- | ---- | ------------------------------------------------------------ |
| keepAlive | boolean | No | Whether to keep the connection alive. The default value is **false**. |
| OOBInline | boolean | No | Whether to enable OOBInline. The default value is **false**. |
| TCPNoDelay | boolean | No | Whether to enable no-delay on the TCPSocket connection. The default value is **false**. |
| TCPNoDelay | boolean | No | Whether to enable no-delay on the TCP socket connection. The default value is **false**. |
| socketLinger | Object | Yes | Socket linger.<br>- **on**: whether to enable socket linger. The value true means to enable socket linger and false means the opposite.<br>- **linger**: linger time, in ms. The value ranges from **0** to **65535**.<br>Specify this parameter only when **on** is set to **true**.|
| receiveBufferSize | number | No | Size of the receive buffer, in bytes. The default value is **0**. |
| sendBufferSize | number | No | Size of the send buffer, in bytes. The default value is **0**. |
| reuseAddress | boolean | No | Whether to reuse addresses. The default value is **false**. |
| socketTimeout | number | No | Timeout duration of the UDPSocket connection, in ms. The default value is **0**. |
| socketTimeout | number | No | Timeout duration of the UDP socket connection, in ms. The default value is **0**. |
## socket.constructTCPSocketServerInstance<sup>10+</sup>
......@@ -1602,10 +1689,10 @@ Defines a TCPSocketServer connection. Before calling TCPSocketServer APIs, you n
listen(address: NetAddress, callback: AsyncCallback\<void\>): void
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCPSocket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses an asynchronous callback to return the result.
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCP socket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses an asynchronous callback to return the result.
> **NOTE**
> The server uses this API to perform the bind, listen, and accept operations.
> The server uses this API to perform the **bind**, **listen**, and **accept** operations. If the **bind** operation fails, the system randomly allocates a port number.
**Required permissions**: ohos.permission.INTERNET
......@@ -1647,10 +1734,10 @@ tcpServer.listen({ address: "192.168.xx.xxx", port: xxxx, family: 1 }, err => {
listen(address: NetAddress): Promise\<void\>
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCPSocket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses a promise to return the result.
Binds the IP address and port number. The port number can be specified or randomly allocated by the system. The server listens to and accepts TCP socket connections established over the socket. Multiple threads are used to process client data concurrently. This API uses a promise to return the result.
> **NOTE**
> The server uses this API to perform the bind, listen, and accept operations.
> The server uses this API to perform the **bind**, **listen**, and **accept** operations. If the **bind** operation fails, the system randomly allocates a port number.
**Required permissions**: ohos.permission.INTERNET
......@@ -1908,7 +1995,10 @@ promise.then(() => {
on(type: 'connect', callback: Callback\<TCPSocketConnection\>): void
Enables listening for TCPSocketServer connection events. This API uses an asynchronous callback to return the result.
Subscribes to TCPSocketServer connection events. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1938,10 +2028,10 @@ tcpServer.on('connect', function(data) {
off(type: 'connect', callback?: Callback\<TCPSocketConnection\>): void
Disables listening for TCPSocketServer connection events. This API uses an asynchronous callback to return the result.
Unsubscribes from TCPSocketServer connection events. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -1966,7 +2056,7 @@ let callback = data => {
console.log('on connect message: ' + JSON.stringify(data));
}
tcpServer.on('connect', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcpServer.off('connect', callback);
tcpServer.off('connect');
```
......@@ -1975,7 +2065,10 @@ tcpServer.off('connect');
on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the TCPSocketServer connection. This API uses an asynchronous callback to return the result.
Subscribes to **error** events of the TCPSocketServer connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2005,10 +2098,10 @@ tcpServer.on('error', err => {
off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the TCPSocketServer connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **error** events of the TCPSocketServer connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2033,7 +2126,7 @@ let callback = err => {
console.log("on error, err:" + JSON.stringify(err));
}
tcpServer.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tcpServer.off('error', callback);
tcpServer.off('error');
```
......@@ -2147,7 +2240,7 @@ tcpServer.on('connect', function(client) {
close(callback: AsyncCallback\<void\>): void
Closes a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
Closes a TCP socket connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
......@@ -2186,7 +2279,7 @@ tcpServer.on('connect', function(client) {
close(): Promise\<void\>
Closes a **TCPSocketConnection** object. This API uses a promise to return the result.
Closes a TCP socket connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
......@@ -2307,7 +2400,7 @@ tcpServer.on('connect', function(client) {
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for **message** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
Subscribes to **message** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2346,10 +2439,10 @@ tcpServer.on('connect', function(client) {
off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for **message** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
Unsubscribes from **message** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2382,7 +2475,7 @@ let callback = value => {
let tcpServer = socket.constructTCPSocketServerInstance();
tcpServer.on('connect', function(client) {
client.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('message', callback);
client.off('message');
});
......@@ -2392,7 +2485,7 @@ tcpServer.on('connect', function(client) {
on(type: 'close', callback: Callback\<void\>): void
Enables listening for **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
Subscribes to **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2424,10 +2517,10 @@ tcpServer.on('connect', function(client) {
on(type: 'close', callback: Callback\<void\>): void
Disables listening for **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
Unsubscribes from **close** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2453,7 +2546,7 @@ let callback = () => {
let tcpServer = socket.constructTCPSocketServerInstance();
tcpServer.on('connect', function(client) {
client.on('close', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('close', callback);
client.off('close');
});
......@@ -2463,7 +2556,7 @@ tcpServer.on('connect', function(client) {
on(type: 'error', callback: ErrorCallback): void
Enables listening for **error** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
Subscribes to **error** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2495,10 +2588,10 @@ tcpServer.on('connect', function(client) {
off(type: 'error', callback?: ErrorCallback): void
Disables listening for **error** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
Unsubscribes from **error** events of a **TCPSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2524,7 +2617,7 @@ let callback = err => {
let tcpServer = socket.constructTCPSocketServerInstance();
tcpServer.on('connect', function(client) {
client.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('error', callback);
client.off('error');
});
......@@ -2558,7 +2651,7 @@ let tls = socket.constructTLSSocketInstance();
## TLSSocket<sup>9+</sup>
Defines a TLSSocket connection. Before calling TLSSocket APIs, you need to call [socket.constructTLSSocketInstance](#socketconstructtlssocketinstance9) to create a **TLSSocket** object.
Defines a TLS socket connection. Before calling TLSSocket APIs, you need to call [socket.constructTLSSocketInstance](#socketconstructtlssocketinstance9) to create a **TLSSocket** object.
### bind<sup>9+</sup>
......@@ -2644,7 +2737,7 @@ promise.then(() => {
getState(callback: AsyncCallback\<SocketStateBase\>): void
Obtains the status of the TLSSocket connection. This API uses an asynchronous callback to return the result.
Obtains the status of the TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2652,7 +2745,7 @@ Obtains the status of the TLSSocket connection. This API uses an asynchronous ca
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------ | ---- | ---------- |
| callback | AsyncCallback\<[SocketStateBase](#socketstatebase)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLSSocket connection is returned. If the operation fails, an error message is returned.|
| callback | AsyncCallback\<[SocketStateBase](#socketstatebase)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLS socket connection is returned. If the operation fails, an error message is returned.|
**Error codes**
......@@ -2684,7 +2777,7 @@ tls.getState((err, data) => {
getState(): Promise\<SocketStateBase\>
Obtains the status of the TLSSocket connection. This API uses a promise to return the result.
Obtains the status of the TLS socket connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2722,7 +2815,7 @@ promise.then(() => {
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the TCPSocket connection after **bind** is successfully called. This API uses an asynchronous callback to return the result.
Sets other properties of the TCP socket connection after **bind** is successfully called. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2730,8 +2823,8 @@ Sets other properties of the TCPSocket connection after **bind** is successfully
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, the result of setting other properties of the TCPSocket connection is returned. If the operation fails, an error message is returned.|
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, the result of setting other properties of the TCP socket connection is returned. If the operation fails, an error message is returned.|
**Error codes**
......@@ -2774,7 +2867,7 @@ tls.setExtraOptions({
setExtraOptions(options: TCPExtraOptions): Promise\<void\>
Sets other properties of the TCPSocket connection after **bind** is successfully called. This API uses a promise to return the result.
Sets other properties of the TCP socket connection after **bind** is successfully called. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2782,7 +2875,7 @@ Sets other properties of the TCPSocket connection after **bind** is successfully
| Name | Type | Mandatory| Description |
| ------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCPSocket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
| options | [TCPExtraOptions](#tcpextraoptions) | Yes | Other properties of the TCP socket connection. For details, see [TCPExtraOptions](#tcpextraoptions).|
**Return value**
......@@ -2829,7 +2922,7 @@ promise.then(() => {
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void;
Enables listening for **message** events of the TLSSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to **message** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2860,10 +2953,10 @@ tls.on('message', value => {
off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for **message** events of the TLSSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **message** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2872,7 +2965,7 @@ Disables listening for **message** events of the TLSSocket connection. This API
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | ---- | ----------------------------------------- |
| type | string | Yes | Type of the event to subscribe to.<br/> **message**: message receiving event.|
| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result.<br/> **message**: received message.<br>**remoteInfo**: socket connection information.|
| callback | Callback<{message: ArrayBuffer, remoteInfo: [SocketRemoteInfo](#socketremoteinfo)}> | No | Callback used to return the result.<br> **message**: received message.<br>**remoteInfo**: socket connection information.|
**Example**
......@@ -2889,14 +2982,14 @@ let callback = value => {
console.log('remoteInfo: ' + JSON.stringify(value.remoteInfo));
}
tls.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tls.off('message', callback);
```
### on('connect' | 'close')<sup>9+</sup>
on(type: 'connect' | 'close', callback: Callback\<void\>): void
Enables listening for **connect** or **close** events of the TLSSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to **connect** or **close** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2923,10 +3016,10 @@ tls.on('close', () => {
off(type: 'connect' | 'close', callback?: Callback\<void\>): void
Disables listening for **connect** or **close** events of the TLSSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **connect** or **close** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2945,14 +3038,14 @@ let callback1 = () => {
console.log("on connect success");
}
tls.on('connect', callback1);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tls.off('connect', callback1);
tls.off('connect');
let callback2 = () => {
console.log("on close success");
}
tls.on('close', callback2);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tls.off('close', callback2);
```
......@@ -2960,7 +3053,7 @@ tls.off('close', callback2);
on(type: 'error', callback: ErrorCallback): void
Enables listening for error events of the TLSSocket connection. This API uses an asynchronous callback to return the result.
Subscribes to **error** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -2984,10 +3077,10 @@ tls.on('error', err => {
off(type: 'error', callback?: ErrorCallback): void
Disables listening for error events of the TLSSocket connection. This API uses an asynchronous callback to return the result.
Unsubscribes from **error** events of the TLS socket connection. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3006,7 +3099,7 @@ let callback = err => {
console.log("on error, err:" + JSON.stringify(err));
}
tls.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tls.off('error', callback);
```
......@@ -3014,7 +3107,7 @@ tls.off('error', callback);
connect(options: TLSConnectOptions, callback: AsyncCallback\<void\>): void
Sets up a TLSSocket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses an asynchronous callback to return the result.
Sets up a TLS socket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3022,7 +3115,7 @@ Sets up a TLSSocket connection, and creates and initializes a TLS session after
| Name | Type | Mandatory| Description|
| -------- | ---------------------------------------| ----| --------------- |
| options | [TLSConnectOptions](#tlsconnectoptions9) | Yes | Parameters required for the TLSSocket connection.|
| options | [TLSConnectOptions](#tlsconnectoptions9) | Yes | Parameters required for the TLS socket connection.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
**Error codes**
......@@ -3108,7 +3201,7 @@ tlsOneWay.connect(oneWayOptions, (err, data) => {
connect(options: TLSConnectOptions): Promise\<void\>
Sets up a TLSSocket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. Both two-way and one-way authentication modes are supported. This API uses a promise to return the result.
Sets up a TLS socket connection, and creates and initializes a TLS session after **bind** is successfully called. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. Both two-way and one-way authentication modes are supported. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3209,7 +3302,7 @@ tlsOneWay.connect(oneWayOptions).then(data => {
getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void
Obtains the remote address of a TLSSocket connection. This API uses an asynchronous callback to return the result.
Obtains the remote address of a TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3242,7 +3335,7 @@ tls.getRemoteAddress((err, data) => {
getRemoteAddress(): Promise\<NetAddress\>
Obtains the remote address of a TLSSocket connection. This API uses a promise to return the result.
Obtains the remote address of a TLS socket connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3274,7 +3367,7 @@ promise.then(() => {
getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void
Obtains the local digital certificate after a TLSSocket connection is established. This API is applicable to two-way authentication. It uses an asynchronous callback to return the result.
Obtains the local digital certificate after a TLS socket connection is established. This API is applicable to two-way authentication. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3308,7 +3401,7 @@ tls.getCertificate((err, data) => {
getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
Obtains the local digital certificate after a TLSSocket connection is established. This API is applicable to two-way authentication. It uses a promise to return the result.
Obtains the local digital certificate after a TLS socket connection is established. This API is applicable to two-way authentication. It uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3340,7 +3433,7 @@ tls.getCertificate().then(data => {
getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void
Obtains the digital certificate of the server after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
Obtains the digital certificate of the server after a TLS socket connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3373,7 +3466,7 @@ tls.getRemoteCertificate((err, data) => {
getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
Obtains the digital certificate of the server after a TLSSocket connection is established. This API uses a promise to return the result.
Obtains the digital certificate of the server after a TLS socket connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3404,7 +3497,7 @@ tls.getRemoteCertificate().then(data => {
getProtocol(callback: AsyncCallback\<string\>): void
Obtains the communication protocol version after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
Obtains the communication protocol version after a TLS socket connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3438,7 +3531,7 @@ tls.getProtocol((err, data) => {
getProtocol():Promise\<string\>
Obtains the communication protocol version after a TLSSocket connection is established. This API uses a promise to return the result.
Obtains the communication protocol version after a TLS socket connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3470,7 +3563,7 @@ tls.getProtocol().then(data => {
getCipherSuite(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the cipher suite negotiated by both communication parties after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
Obtains the cipher suite negotiated by both communication parties after a TLS socket connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3505,7 +3598,7 @@ tls.getCipherSuite((err, data) => {
getCipherSuite(): Promise\<Array\<string\>\>
Obtains the cipher suite negotiated by both communication parties after a TLSSocket connection is established. This API uses a promise to return the result.
Obtains the cipher suite negotiated by both communication parties after a TLS socket connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3538,7 +3631,7 @@ tls.getCipherSuite().then(data => {
getSignatureAlgorithms(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the signing algorithm negotiated by both communication parties after a TLSSocket connection is established. This API is applicable to two-way authentication. It uses an asynchronous callback to return the result.
Obtains the signing algorithm negotiated by both communication parties after a TLS socket connection is established. This API is applicable to two-way authentication. It uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3571,7 +3664,7 @@ tls.getSignatureAlgorithms((err, data) => {
getSignatureAlgorithms(): Promise\<Array\<string\>\>
Obtains the signing algorithm negotiated by both communication parties after a TLSSocket connection is established. This API is applicable to two-way authentication. It uses a promise to return the result.
Obtains the signing algorithm negotiated by both communication parties after a TLS socket connection is established. This API is applicable to two-way authentication. It uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3602,7 +3695,7 @@ tls.getSignatureAlgorithms().then(data => {
send(data: string, callback: AsyncCallback\<void\>): void
Sends a message to the server after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
Sends a message to the server after a TLS socket connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3640,7 +3733,7 @@ tls.send("xxxx", (err) => {
send(data: string): Promise\<void\>
Sends a message to the server after a TLSSocket connection is established. This API uses a promise to return the result.
Sends a message to the server after a TLS socket connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3681,7 +3774,7 @@ tls.send("xxxx").then(() => {
close(callback: AsyncCallback\<void\>): void
Closes a TLSSocket connection. This API uses an asynchronous callback to return the result.
Closes a TLS socket connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3717,7 +3810,7 @@ tls.close((err) => {
close(): Promise\<void\>
Closes a TLSSocket connection. This API uses a promise to return the result.
Closes a TLS socket connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -3815,7 +3908,7 @@ let tlsServer = socket.constructTLSSocketServerInstance();
## TLSSocketServer<sup>10+</sup>
Defines a TLSSocketServer connection. Before calling TLSSocketServer APIs, you need to call [socket.constructTLSSocketServerInstance](#socketconstructtlssocketserverinstance10) to create a **TLSSocketServer** object.
Defines a TLS socket server connection. Before calling TLSSocketServer APIs, you need to call [socket.constructTLSSocketServerInstance](#socketconstructtlssocketserverinstance10) to create a **TLSSocketServer** object.
### listen<sup>10+</sup>
......@@ -3950,7 +4043,7 @@ tlsServer.listen(options).then(() => {
getState(callback: AsyncCallback\<SocketStateBase\>): void
Obtains the status of the TLSSocketServer connection upon successful listening. This API uses an asynchronous callback to return the result.
Obtains the status of the TLS socket server connection upon successful listening. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -3961,7 +4054,7 @@ Obtains the status of the TLSSocketServer connection upon successful listening.
| Name | Type | Mandatory| Description |
| -------- | ---------------------------------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback\<[SocketStateBase](#socketstatebase7)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLSSocketServer connection is returned. If the operation fails, an error message is returned.|
| callback | AsyncCallback\<[SocketStateBase](#socketstatebase7)> | Yes | Callback used to return the result. If the operation is successful, the status of the TLS socket server connection is returned. If the operation fails, an error message is returned.|
**Error codes**
......@@ -4011,7 +4104,7 @@ tlsServer.getState((err, data) => {
getState(): Promise\<SocketStateBase\>
Obtains the status of the TLSSocketServer connection upon successful listening. This API uses a promise to return the result.
Obtains the status of the TLS socket server connection upon successful listening. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4071,7 +4164,7 @@ promise.then(() => {
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
Sets other properties of the TLSSocketServer connection upon successful listening. This API uses an asynchronous callback to return the result.
Sets other properties of the TLS socket server connection upon successful listening. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4082,7 +4175,7 @@ Sets other properties of the TLSSocketServer connection upon successful listenin
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------------------------ |
| options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLSSocketServer connection. |
| options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLS socket server connection. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
**Error codes**
......@@ -4141,7 +4234,7 @@ tlsServer.setExtraOptions({
setExtraOptions(options: TCPExtraOptions): Promise\<void\>
Sets other properties of the TLSSocketServer connection upon successful listening. This API uses a promise to return the result.
Sets other properties of the TLS socket server connection upon successful listening. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4152,7 +4245,7 @@ Sets other properties of the TLSSocketServer connection upon successful listenin
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------ | ---- | ------------------------------- |
| options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLSSocketServer connection.|
| options | [TCPExtraOptions](#tcpextraoptions7) | Yes | Other properties of the TLS socket server connection.|
**Return value**
......@@ -4217,7 +4310,7 @@ promise.then(() => {
getCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void
Obtains the local digital certificate after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result.
Obtains the local digital certificate after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4278,7 +4371,7 @@ tlsServer.getCertificate((err, data) => {
getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
Obtains the local digital certificate after a TLSSocketServer connection is established. This API uses a promise to return the result.
Obtains the local digital certificate after a TLS socket server connection is established. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4338,7 +4431,7 @@ tlsServer.getCertificate().then(data => {
getProtocol(callback: AsyncCallback\<string\>): void
Obtains the communication protocol version after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result.
Obtains the communication protocol version after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4399,7 +4492,7 @@ tlsServer.getProtocol((err, data) => {
getProtocol():Promise\<string\>
Obtains the communication protocol version after a TLSSocketServer connection is established. This API uses a promise to return the result.
Obtains the communication protocol version after a TLS socket server connection is established. This API uses a promise to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4453,11 +4546,11 @@ tlsServer.getProtocol().then(data => {
});
```
### on('connect')
### on('connect')<sup>10+</sup>
on(type: 'connect', callback: Callback\<TLSSocketConnection\>): void
Enables listening for TLSSocketServer connection events. This API uses an asynchronous callback to return the result.
Subscribes to TLS socket server connection events. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4508,14 +4601,14 @@ tlsServer.on('connect', function(data) {
});
```
### off('connect')
### off('connect')<sup>10+</sup>
off(type: 'connect', callback?: Callback\<TLSSocketConnection\>): void
Disables listening for TLSSocketServer connection events. This API uses an asynchronous callback to return the result.
Unsubscribes from TLS socket server connection events. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -4564,16 +4657,16 @@ tlsServer.listen(options).then(() => {
return;
});
tlsServer.on('connect', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tlsServer.off('connect', callback);
tlsServer.off('connect');
```
### on('error')
### on('error')<sup>10+</sup>
on(type: 'error', callback: ErrorCallback): void
Enables listening for **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result.
Subscribes to **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> This API can be called only after **listen** is successfully called.
......@@ -4624,14 +4717,14 @@ tlsServer.on('error', err => {
});
```
### off('error')
### off('error')<sup>10+</sup>
off(type: 'error', callback?: ErrorCallback): void
Disables listening for **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result.
Unsubscribes from **error** events of a **TLSSocketServer** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -4680,7 +4773,7 @@ tlsServer.listen(options).then(() => {
return;
});
tlsServer.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
tlsServer.off('error', callback);
tlsServer.off('error');
```
......@@ -4704,7 +4797,7 @@ Defines a **TLSSocketConnection** object, that is, the connection between the TL
send(data: string, callback: AsyncCallback\<void\>): void
Sends a message to the client after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result.
Sends a message to the client after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -4712,7 +4805,7 @@ Sends a message to the client after a TLSSocketServer connection is established.
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------------ |
| data | string | Yes | Parameters for sending data over the TLSSocketServer connection. |
| data | string | Yes | Parameters for sending data over the TLS socket server connection. |
| callback | AsyncCallback\<void\> | Yes | Callback used to return the result. If the operation is successful, no value is returned. If the operation fails, an error message is returned.|
**Error codes**
......@@ -4767,7 +4860,7 @@ tlsServer.on('connect', function(client) {
send(data: string): Promise\<void\>
Sends a message to the server after a TLSSocketServer connection is established. This API uses a promise to return the result.
Sends a message to the server after a TLS socket server connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -4775,7 +4868,7 @@ Sends a message to the server after a TLSSocketServer connection is established.
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------- |
| data | string | Yes | Parameters required for the TLSSocketServer connection.|
| data | string | Yes | Parameters required for the TLS socket server connection.|
**Return value**
......@@ -4836,7 +4929,7 @@ tlsServer.on('connect', function(client) {
close(callback: AsyncCallback\<void\>): void
Closes a TLSSocketServer connection. This API uses an asynchronous callback to return the result.
Closes a TLS socket server connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -4897,7 +4990,7 @@ tlsServer.on('connect', function(client) {
close(): Promise\<void\>
Closes a TLSSocketServer connection. This API uses a promise to return the result.
Closes a TLS socket server connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -4958,7 +5051,7 @@ tlsServer.on('connect', function(client) {
getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void
Obtains the remote address of a TLSSocketServer connection. This API uses an asynchronous callback to return the result.
Obtains the remote address of a TLS socket server connection. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5017,7 +5110,7 @@ tlsServer.on('connect', function(client) {
getRemoteAddress(): Promise\<NetAddress\>
Obtains the remote address of a TLSSocketServer connection. This API uses a promise to return the result.
Obtains the remote address of a TLS socket server connection. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5075,7 +5168,7 @@ tlsServer.on('connect', function(client) {
getRemoteCertificate(callback: AsyncCallback\<[X509CertRawData](#x509certrawdata9)\>): void
Obtains the digital certificate of the peer end after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result. It applies only to the scenario where the client sends a certificate to the server.
Obtains the digital certificate of the peer end after a TLS socket server connection is established. This API uses an asynchronous callback to return the result. It applies only to the scenario where the client sends a certificate to the server.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5134,7 +5227,7 @@ tlsServer.on('connect', function(client) {
getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)\>
Obtains the digital certificate of the peer end after a TLSSocketServer connection is established. This API uses a promise to return the result. It applies only to the scenario where the client sends a certificate to the server.
Obtains the digital certificate of the peer end after a TLS socket server connection is established. This API uses a promise to return the result. It applies only to the scenario where the client sends a certificate to the server.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5192,7 +5285,7 @@ tlsServer.on('connect', function(client) {
getCipherSuite(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the cipher suite negotiated by both communication parties after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result.
Obtains the cipher suite negotiated by both communication parties after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5253,7 +5346,7 @@ tlsServer.on('connect', function(client) {
getCipherSuite(): Promise\<Array\<string\>\>
Obtains the cipher suite negotiated by both communication parties after a TLSSocketServer connection is established. This API uses a promise to return the result.
Obtains the cipher suite negotiated by both communication parties after a TLS socket server connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5313,7 +5406,7 @@ tlsServer.on('connect', function(client) {
getSignatureAlgorithms(callback: AsyncCallback\<Array\<string\>\>): void
Obtains the signing algorithm negotiated by both communication parties after a TLSSocketServer connection is established. This API uses an asynchronous callback to return the result.
Obtains the signing algorithm negotiated by both communication parties after a TLS socket server connection is established. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5372,7 +5465,7 @@ tlsServer.on('connect', function(client) {
getSignatureAlgorithms(): Promise\<Array\<string\>\>
Obtains the signing algorithm negotiated by both communication parties after a TLSSocketServer connection is established. This API uses a promise to return the result.
Obtains the signing algorithm negotiated by both communication parties after a TLS socket server connection is established. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5430,7 +5523,7 @@ tlsServer.on('connect', function(client) {
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Enables listening for **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
Subscribes to **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5491,10 +5584,10 @@ tlsServer.on('connect', function(client) {
off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
Disables listening for **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
Unsubscribes from **message** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5551,7 +5644,7 @@ tlsServer.listen(options).then(() => {
});
tlsServer.on('connect', function(client) {
client.on('message', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('message', callback);
client.off('message');
});
......@@ -5561,7 +5654,7 @@ tlsServer.on('connect', function(client) {
on(type: 'close', callback: Callback\<void\>): void
Enables listening for **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
Subscribes to **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5615,10 +5708,10 @@ tlsServer.on('connect', function(client) {
on(type: 'close', callback: Callback\<void\>): void
Disables listening for **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
Unsubscribes from **close** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5668,7 +5761,7 @@ tlsServer.listen(options).then(() => {
});
tlsServer.on('connect', function(client) {
client.on('close', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('close', callback);
client.off('close');
});
......@@ -5678,7 +5771,7 @@ tlsServer.on('connect', function(client) {
on(type: 'error', callback: ErrorCallback): void
Enables listening for **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
Subscribes to **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5732,10 +5825,10 @@ tlsServer.on('connect', function(client) {
off(type: 'error', callback?: ErrorCallback): void
Disables listening for **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
Unsubscribes from **error** events of a **TLSSocketConnection** object. This API uses an asynchronous callback to return the result.
> **NOTE**
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events.
> You can pass the callback of the **on** function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
**System capability**: SystemCapability.Communication.NetStack
......@@ -5785,7 +5878,7 @@ tlsServer.listen(options).then(() => {
});
tlsServer.on('connect', function(client) {
client.on('error', callback);
// You can pass the callback of the on method to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
// You can pass the callback of the on function if you want to cancel listening for a certain type of events. If you do not pass the callback, you will cancel listening for all events.
client.off('error', callback);
client.off('error');
});
......
# i18n Error Codes
# I18N Error Codes
> **NOTE**
>
......@@ -8,7 +8,7 @@
**Error Message**
Unspported para value.
param value not valid
**Description**
......@@ -17,25 +17,7 @@ This error code is reported if an I18N API is called with invalid parameter valu
**Possible Causes**
Invalid parameter values are probably due to incorrect parameter types.
**Solution**
Check whether the parameter type is correct.
## 890002 Incorrect Configuration Option
**Error Message**
param value not valid
**Description**
This error code is reported if an I18N API is called with invalid option values specified.
**Possible Causes**
Invalid option values are probably due to incorrect option types.
**Solution**
Check whether the option type is correct.
......@@ -157,8 +157,9 @@ You must install **Node.js** and HPM on your local PC. The installation procedur
2. Learn more about the distribution.
1. Read carefully the information about the distribution to learn its application scenarios, features, components, usage, and customization methods.
2. Click **Download** if you want to download the distribution to your local PC.
3. Click **Device component tailoring** if you want to add or delete components of the distribution.
2. Use either of the following modes to obtain the source code:
- Click **Download** if you want to download the distribution to your local PC.
- Click **Device component tailoring** if you want to add or delete components of the distribution.
**Figure 2** Example distribution
......@@ -200,12 +201,12 @@ The table below provides only the sites for downloading the latest OpenHarmony L
| Hi3516 solution-Linux (binary)| 3.0 | [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_taurus_linux.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/3.0/hispark_taurus_linux.tar.gz.sha256) | 418.1 MB |
| RELEASE-NOTES | 3.0 | [Download](https://gitee.com/openharmony/docs/blob/OpenHarmony-3.0-LTS/en/release-notes/OpenHarmony-v3.0-LTS.md)| - | - |
| **Source Code of the Latest Release**| **Version**| **Site**| **SHA-256 Checksum**| **Software Package Size**|
| Full code base (for mini, small, and standard systems) | 4.0 Beta1 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/code-v4.0-Beta1.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/code-v4.0-Beta1.tar.gz.sha256)| 26.2 GB |
| Hi3861 solution (binary) | 4.0 Beta1 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/hispark_pegasus.tar.gz) | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/hispark_pegasus.tar.gz.sha256)| 25.1 MB |
| Hi3516 solution-LiteOS (binary)| 4.0 Beta1 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/hispark_taurus_LiteOS.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/hispark_taurus_LiteOS.tar.gz.sha256)| 287.6 MB |
| Hi3516 solution-Linux (binary) | 4.0 Beta1 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/hispark_taurus_Linux.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/hispark_taurus_Linux.tar.gz.sha256)| 186.4 MB |
| RK3568 standard system solution (binary) | 4.0 Beta1 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/dayu200_standard_arm32.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta1/dayu200_standard_arm32.tar.gz.sha256)| 4.5 GB |
| RELEASE-NOTES | 4.0 Beta1 | [Download](../../release-notes/OpenHarmony-v4.0-beta1.md)| - | - |
| Full code base (for mini, small, and standard systems) | 4.0 Beta2 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/code-v4.0-Beta2.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/code-v4.0-Beta2.tar.gz.sha256)| 27.7 GB |
| Hi3861 solution (binary) | 4.0 Beta2 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/hispark_pegasus.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/hispark_pegasus.tar.gz.sha256)| 27.5 MB |
| Hi3516 solution-LiteOS (binary)| 4.0 Beta2 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/hispark_taurus_LiteOS.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/hispark_taurus_LiteOS.tar.gz.sha256)| 300.9 MB |
| Hi3516 solution-Linux (binary) | 4.0 Beta2 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/hispark_taurus_Linux.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/hispark_taurus_Linux.tar.gz.sha256)| 192.4 MB |
| RK3568 standard system solution (binary) | 4.0 Beta2 | [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/dayu200_standard_arm32.tar.gz)| [Download](https://repo.huaweicloud.com/openharmony/os/4.0-Beta2/dayu200_standard_arm32.tar.gz.sha256)| 5.2 GB |
| RELEASE-NOTES | 4.0 Beta2 | [Download](../../release-notes/OpenHarmony-v4.0-beta2.md) | - | - |
| **Compiler Toolchain**| **Version**| **Site**| **SHA-256 Checksum**| **Software Package Size**|
| Compiler toolchain| - | [Download](https://repo.huaweicloud.com/openharmony/os/2.0/tool_chain/)| - | - |
......
# USB Manager Changelog
## cl.usb_manager.1 Error Information Return Method Change
The USB Manager API uses service logic return values to indicate error information, which does not comply with the API error code specifications of OpenHarmony. Beginning from API version 9, error information is returned by throwing exceptions.
**Change Impact**
The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected.
**Key API/Component Changes**
Changed the USB module name from **@ohos.usb.d.ts** to **@ohos.usbV9.d.ts**, and added error code processing for all APIs in the module.
**Adaptation Guide**
Take the **getDevices** API as an example. The sample code is as follows:
```ts
import usbV9 from '@ohos.usbV9'
try {
usbV9.getDevices(); // If an improper parameter is passed to this API, an exception will be thrown.
} catch (err) {
console.error("getDevices errCode:" + err.code + ",errMessage:" + err.message);
}
```
# Location Subsystem ChangeLog
## cl.location.1 Migration of System APIs and APIs in API Version 9 to the New @ohos.geoLocationManager.d.ts
The APIs in **@ohos.geolocation.d.ts** do not support throwing error codes. However, APIs in API version 9 and system APIs are required to support throwing of error codes. To support this function, all system APIs and APIs in API version 9 in **@ohos.geolocation.d.ts** are migrated to the newly added **@ohos.geoLocationManager.d.ts** file, and corresponding error code description is added.
To use system APIs and APIs in API version 9 of the location subsystem, you need to import **@ohos.geoLocationManager**.
import geoLocationManager from '@ohos.geoLocationManager';
**Change Impact**
System APIs and APIs in API version 9 are affected. To ensure normal use of these APIs, you need to import **@ohos.geoLocationManager**.
import geoLocationManager from '@ohos.geoLocationManager';
Other APIs are not affected.
**Key API/Component Changes**
| Class| API Type| Declaration| Change Type|
| -- | -- | -- | -- |
|geolocation| namespace | declare namespacegeolocation| Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation | interface | export interface ReverseGeocodingMockInfo | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation | interface | export interface LocationMockConfig | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation | interface | export interface CountryCode | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation | enum | export enum CountryCodeType | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation.GeoAddress | field | isFromMock?: Boolean; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation.Location | field | isFromMock?: Boolean; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation.GeoLocationErrorCode | field | NOT_SUPPORTED = 100 | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation.GeoLocationErrorCode | field | QUERY_COUNTRY_CODE_ERROR | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation| method | function on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation| method | function off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation| method | function getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation| method | function getCountryCode(): Promise&lt;CountryCode&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation| method | function enableLocationMock(scenario: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;): void; | Deleted this API in API version 9.|
|geolocation| method | function enableLocationMock(callback: AsyncCallback&lt;void&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation| method | function enableLocationMock(scenario: LocationRequestScenario): Promise&lt;void&gt;; | Deleted this API in API version 9.|
|geolocation| method | function enableLocationMock(): Promise&lt;void&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
|geolocation| method | function disableLocationMock(scenario: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;): void; | Deleted this API in API version 9.|
|geolocation| method | function disableLocationMock(callback: AsyncCallback&lt;void&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function disableLocationMock(scenario: LocationRequestScenario): Promise&lt;void&gt;; | Deleted this API in API version 9.|
|geolocation| method | function disableLocationMock(): Promise&lt;void&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function setMockedLocations(config: LocationMockConfig, callback: AsyncCallback&lt;void&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function setMockedLocations(config: LocationMockConfig): Promise&lt;void&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function enableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function enableReverseGeocodingMock(): Promise&lt;void&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function disableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function disableReverseGeocodingMock(): Promise&lt;void&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;, callback: AsyncCallback&lt;void&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;): Promise&lt;void&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function isLocationPrivacyConfirmed(type: LocationPrivacyType, callback: AsyncCallback&lt;boolean&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function isLocationPrivacyConfirmed(type: LocationPrivacyType): Promise&lt;boolean&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
|geolocation| method | function setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean, callback: AsyncCallback&lt;boolean&gt;): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts** and changed the return value in the callback to **void**. |
|geolocation| method | function setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean): Promise&lt;boolean&gt;; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts** and changed the return value in the promise to **void**. |
**(Optional) Adaptation Guide**
The following sample code shows how to call **enableLocation** in the new version:
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
geoLocationManager.enableLocation((err, data) => {
if (err) {
console.log('enableLocation: err=' + JSON.stringify(err));
}
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## cl.location.2 Location Service Permission Change
From API version 9, the **ohos.permission.APPROXIMATELY_LOCATION** permission is added for obtaining the approximate location.
If you use API version 9 or later, you need to apply for both the **ohos.permission.LOCATION** and **ohos.permission.APPROXIMATELY_LOCATION** permissions. Applying for only the **ohos.permission.LOCATION** permission will fail.
**Change Impact**
Applications using API versions earlier than 9 are not affected. For an application using API version 9 or later, the method for applying for the location permission is changed. The details are as follows:
Before using basic location capabilities, check whether your application has been granted the permission to access the device location information. If not, your application needs to obtain the permission from the user as described below.
The system provides the following location permissions:
- ohos.permission.LOCATION
- ohos.permission.APPROXIMATELY_LOCATION
- ohos.permission.LOCATION_IN_BACKGROUND
If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:
API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
API version 9 and later: Apply for **ohos.permission.APPROXIMATELY_LOCATION**, or apply for **ohos.permission.APPROXIMATELY_LOCATION** and **ohos.permission.LOCATION**. Note that **ohos.permission.LOCATION** cannot be applied for separately.
| API Version| Location Permission| Permission Application Result| Location Accuracy|
| -------- | -------- | -------- | -------- |
| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
| 9 and later| ohos.permission.LOCATION | Failed| No location obtained.|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers.|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION_IN_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
You can declare the required permissions in your application's configuration file. For details, see the [permission application guide](../../../application-dev/security/accesstoken-guidelines.md).
**Key API/Component Changes**
Applications using API versions earlier than 9 are not affected.
If your application uses API version 9 or later and needs to call APIs requiring the **ohos.permission.LOCATION** permission in **@ohos.geolocation** and **@ohos.geoLocationManager**, you need to apply for the corresponding permission as described previously.
# Globalization Subsystem ChangeLog
## cl.global.1 Support of Error Codes for the Internalization Module
APIs provided by the internationalization module of the globalization subsystem are changed to support error codes in the following scenarios. The following changes are made in API version 9 and later:
- Obtaining the local expression of a country or language
- Obtaining the list of languages supported by the system and the list of areas supported by a language
- Checking whether a language matches an area
- Obtaining and setting the system language, country or region, and area
- Obtaining and setting the 24-hour clock of the system
- Obtaining, adding, and removing the preferred language
- Obtaining and setting localized numbers
You need to adapt your application.
**Change Impact**
The preceding APIs are changed to the static methods of the **System** class. When such an API is called, add the class name to the end of the module name.
For setter APIs, the type of the return value is changed from boolean to void, for example, **setSystemLanguage**.
When a call to an API fails, an error code is returned according to the failure cause. For example, when permissions are not correctly configured for an application, **201** is returned.
**Key API/Component Changes**
- Involved APIs:
- getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string;
- getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string;
- getSystemLanguages(): Array<string>;
- getSystemCountries(language: string): Array<string>;
- isSuggested(language: string, region?: string): boolean;
- getSystemLanguage(): string;
- setSystemLanguage(language: string): void;
- getSystemRegion(): string;
- setSystemRegion(region: string): void;
- getSystemLocale(): string;
- setSystemLocale(locale: string): void;
- is24HourClock(): boolean;
- set24HourClock(option: boolean): void;
- addPreferredLanguage(language: string, index?: number): void;
- removePreferredLanguage(index: number): void;
- getPreferredLanguageList(): Array<string>;
- getFirstPreferredLanguage(): string;
- getAppPreferredLanguage(): string;
- setUsingLocalDigit(flag: boolean): void;
- getUsingLocalDigit(): boolean;
**Adaptation Guide**
Use the **try-catch** block to capture errors returned by an API.
```
import I18n from '@ohos.i18n'
try {
I18n.System.setSystemLanguage('zh');
} catch(error) {
console.error(`call System.setSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`)
}
```
# Power Subsystem ChangeLog
## cl.powermgr.1 Error Information Return Method Change of APIs
The **power** module uses service logic return values to indicate error information, which does not comply with the API error code specifications of OpenHarmony. Therefore, modification is made in API version 9 and later.
- Power consumption statistics: [@ohos.batteryStatistics](../../../application-dev/reference/apis/js-apis-batteryStatistics.md)
- Screen brightness: [@ohos.brightness](../../../application-dev/reference/apis/js-apis-brightness.md)
- Power management: [@ohos.power](../../../application-dev/reference/apis/js-apis-power.md)
- Runninglock management: [@ohos.runningLock](../../../application-dev/reference/apis/js-apis-runninglock.md)
- Thermal management: [@ohos.thermal](../../../application-dev/reference/apis/js-apis-thermal.md)
Asynchronous API: An error message is returned via **AsyncCallback** or the **error** object of **Promise**.
Synchronous API: An error message is returned via an exception.
#### Change Impact
The application developed based on earlier versions needs to adapt the method for returning API error information. Otherwise, the original service logic will be affected.
#### Key API/Component Changes
Error code processing is added for the following APIs:
- getBatteryStats(callback: AsyncCallback<Array&lt;BatteryStatsInfo&gt;>): void
- getAppPowerValue(uid: number): number
- getAppPowerPercent(uid: number): number
- getHardwareUnitPowerValue(type: ConsumptionType): number
- getHardwareUnitPowerPercent(type: ConsumptionType): number
- setValue(value: number): void
- shutdown(reason: string): void;
- isActive(): boolean
- wakeup(detail: string): void
- suspend(): void
- getPowerMode(): DevicePowerMode
- setPowerMode(mode: DevicePowerMode, callback: AsyncCallback&lt;void&gt;): void
- setPowerMode(mode: DevicePowerMode): Promise&lt;void&gt;
- hold(timeout: number): void
- isHolding(): boolean
- unhold(): void
- isSupported(type: RunningLockType): boolean
- isSupported(type: RunningLockType): boolean
- create(name: string, type: RunningLockType, callback: AsyncCallback&lt;RunningLock&gt;): void
- create(name: string, type: RunningLockType): Promise&lt;RunningLock&gt;
- registerThermalLevelCallback(callback: Callback&lt;ThermalLevel&gt;): void
- unregisterThermalLevelCallback(callback?: Callback&lt;void&gt;): void
- getLevel(): ThermalLevel
#### Adaptation Guide
For details, see the API reference document of each API.
## cl.powermgr.2 System API Change
#### Change Impact
The application developed based on earlier versions needs to adapt to new API names and the new method for returning API error information. Otherwise, the original service logic will be affected.
#### Key API/Component Changes
| Bundle Name | Original API | New API |
| ----------- | ------------------------------------ | ------------------------------ |
| @ohos.power | shutdownDevice(reason: string): void | shutdown(reason: string): void |
| @ohos.power | rebootDevice(reason: string): void | reboot(reason: string): void |
| @ohos.power | wakeupDevice(detail: string): void | wakeup(detail: string): void |
| @ohos.power | suspendDevice(): void | suspend(): void |
#### Adaptation Guide
For details, see [@ohos.power](../../../application-dev/reference/apis/js-apis-power.md).
# Upload and Download Subsystem Changelog
## cl.request.1 Changes of Error Code Definitions and Some API Names
## cl.request.1 Changes of Error Code Definitions and API Names
- The processing of the [upload and download error codes](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/errorcodes/errorcode-request.md) is added to the upload and download APIs.
- An error message is returned via **AsyncCallback** or the **error** object of **Promise**. An error message related to the parameter type or quantity is returned via an exception.
- Some APIs need to be replaced with new APIs, and the parameters remain unchanged.
- Processing of [error codes](https://gitee.com/openharmony/docs/blob/master/en/application-dev/reference/errorcodes/errorcode-request.md) is added to the upload and download APIs.
- Error information is returned via the **error** object in **AsyncCallback** or **Promise**. An error message related to the parameter type or quantity is returned via an exception.
- Some APIs are replaced with new APIs, but the parameters remain unchanged.
**Change Impact**
......@@ -12,7 +12,7 @@ The application developed based on earlier versions needs to adapt the method fo
**Key API/Component Changes**
| Module | Class | Method/Attribute/Enumeration/Constant | Change Type |
| Module | Class | Method/Attribute/Enum/Constant | Change Type |
|--------------|--------------|-----------------------------------------------------------------------------------------------------------------------|-----------|
| ohos.request | request | EXCEPTION_PERMISSION | Added|
| ohos.request | request | EXCEPTION_PARAMCHECK | Added|
......@@ -89,7 +89,7 @@ The application developed based on earlier versions needs to adapt the method fo
**Adaptation Guide**
The following uses **downloadFile** as an example to show how it is called in the new version:
The following sample code shows how to call **downloadFile** in the new version:
```ts
try {
......
# Telephony Subsystem ChangeLog
## cl.telephony.1 Input Parameter Change of System APIs of the SMS Module
Input parameters of some system APIs of the SMS module are changed, leading to noncompliance with the API specifications of OpenHarmony. The following changes are made in API version 9 and later:
The **slotId** parameter is added to the **isImsSmsSupported** API, indicating the slot ID.
**Change Impact**
Input parameters of JS APIs need to be adapted for applications developed based on earlier versions. Otherwise, relevant functions will be affected.
**Key API/Component Changes**
- Involved APIs:
isImsSmsSupported(callback: AsyncCallback<boolean>): void;
isImsSmsSupported(): Promise<boolean>;
- Before change:
```js
function isImsSmsSupported(callback: AsyncCallback<boolean>): void;
function isImsSmsSupported(): Promise<boolean>;
```
- After change:
```js
function isImsSmsSupported(slotId: number, callback: AsyncCallback<boolean>): void;
function isImsSmsSupported(slotId: number): Promise<boolean>;
```
**Adaptation Guide**
Add an input parameter. The sample code is as follows:
Callback mode:
```js
let slotId = 0;
sms.isImsSmsSupported(slotId, (err, data) => {
console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`);
});
```
Promise mode:
```js
let slotId = 0;
let promise = sms.isImsSmsSupported(slotId);
promise.then(data => {
console.log(`isImsSmsSupported success, promise: data->${JSON.stringify(data)}`);
}).catch(err => {
console.error(`isImsSmsSupported failed, promise: err->${JSON.stringify(err)}`);
});
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册