提交 e97d8987 编写于 作者: G Gloria

Update docs against 10775+10756+10800+10812+10745

Signed-off-by: wusongqing<wusongqing@huawei.com>
上级 83cff0dc
# Ability Development
- [Ability Framework Overview](ability-brief.md)
- [Context Usage](context-userguide.md)
- FA Model
......@@ -19,5 +20,3 @@
- [Ability Assistant Usage](ability-assistant-guidelines.md)
- [ContinuationManager Development](continuationmanager.md)
- [Test Framework Usage](ability-delegator.md)
# Media
- Audio
- [Audio Overview](audio-overview.md)
- [Audio Playback Development](audio-playback.md)
- [Audio Recording Development](audio-recorder.md)
- [Audio Rendering Development](audio-renderer.md)
- [Audio Stream Management Development](audio-stream-manager.md)
- [Audio Capture Development](audio-capturer.md)
- [OpenSL ES Audio Playback Development](opensles-playback.md)
- [OpenSL ES Audio Recording Development](opensles-capture.md)
- [Audio Interruption Mode Development](audio-interruptmode.md)
- Video
- [Video Playback Development](video-playback.md)
- [Video Recording Development](video-recorder.md)
- Image
- Audio
- [Audio Overview](audio-overview.md)
- [Audio Playback Development](audio-playback.md)
- [Audio Recording Development](audio-recorder.md)
- [Audio Rendering Development](audio-renderer.md)
- [Audio Stream Management Development](audio-stream-manager.md)
- [Audio Capture Development](audio-capturer.md)
- [OpenSL ES Audio Playback Development](opensles-playback.md)
- [OpenSL ES Audio Recording Development](opensles-capture.md)
- [Audio Interruption Mode Development](audio-interruptmode.md)
- Video
- [Video Playback Development](video-playback.md)
- [Video Recording Development](video-recorder.md)
- Image
- [Image Development](image.md)
- Camera
- [Camera Development](camera.md)
- [Distributed Camera Development](remote-camera.md)
- Camera
- [Camera Development](camera.md)
- [Distributed Camera Development](remote-camera.md)
......@@ -4,5 +4,4 @@
- [Drawing Development](drawing-guidelines.md)
- [Raw File Development](rawfile-guidelines.md)
- [Native Window Development](native-window-guidelines.md)
- [Using MindSpore Lite for Model Inference](mindspore-lite-guidelines.md)
# Using MindSpore Lite for Model Inference
## When to Use
MindSpore Lite is an AI engine that provides AI model inference for different hardware devices. It has been used in a wide range of fields, such as image classification, target recognition, facial recognition, and character recognition.
This document describes the general development process for MindSpore Lite model inference.
## Basic Concepts
Before getting started, you need to understand the following basic concepts:
**Tensor**: a special data structure that is similar to arrays and matrices. It is a basic data structure used in MindSpore Lite network operations.
**Float16 inference**: a mode in which Float16 is used for inference. Float16, also called half-precision, uses 16 bits to represent a number.
## Available APIs
APIs involved in MindSpore Lite model inference are categorized into context APIs, model APIs, and tensor APIs.
### Context APIs
| API | Description |
| ------------------ | ----------------- |
|OH_AI_ContextHandle OH_AI_ContextCreate()|Creates a context object.|
|void OH_AI_ContextSetThreadNum(OH_AI_ContextHandle context, int32_t thread_num)|Sets the number of runtime threads.|
| void OH_AI_ContextSetThreadAffinityMode(OH_AI_ContextHandle context, int mode)|Sets the affinity mode for binding runtime threads to CPU cores, which are categorized into little cores and big cores depending on the CPU frequency.|
|OH_AI_DeviceInfoHandle OH_AI_DeviceInfoCreate(OH_AI_DeviceType device_type)|Creates a runtime device information object.|
|void OH_AI_ContextDestroy(OH_AI_ContextHandle *context)|Destroys a context object.|
|void OH_AI_DeviceInfoSetEnableFP16(OH_AI_DeviceInfoHandle device_info, bool is_fp16)|Sets whether to enable float16 inference. This function is available only for CPU and GPU devices.|
|void OH_AI_ContextAddDeviceInfo(OH_AI_ContextHandle context, OH_AI_DeviceInfoHandle device_info)|Adds a runtime device information object.|
### Model APIs
| API | Description |
| ------------------ | ----------------- |
|OH_AI_ModelHandle OH_AI_ModelCreate()|Creates a model object.|
|OH_AI_Status OH_AI_ModelBuildFromFile(OH_AI_ModelHandle model, const char *model_path,OH_AI_ModelType odel_type, const OH_AI_ContextHandle model_context)|Loads and builds a MindSpore model from a model file.|
|void OH_AI_ModelDestroy(OH_AI_ModelHandle *model)|Destroys a model object.|
### Tensor APIs
| API | Description |
| ------------------ | ----------------- |
|OH_AI_TensorHandleArray OH_AI_ModelGetInputs(const OH_AI_ModelHandle model)|Obtains the input tensor array structure of a model.|
|int64_t OH_AI_TensorGetElementNum(const OH_AI_TensorHandle tensor)|Obtains the number of tensor elements.|
|const char *OH_AI_TensorGetName(const OH_AI_TensorHandle tensor)|Obtains the name of a tensor.|
|OH_AI_DataType OH_AI_TensorGetDataType(const OH_AI_TensorHandle tensor)|Obtains the tensor data type.|
|void *OH_AI_TensorGetMutableData(const OH_AI_TensorHandle tensor)|Obtains the pointer to variable tensor data.|
## How to Develop
The following figure shows the development process for MindSpore Lite model inference.
**Figure 1** Development process for MindSpore Lite model inference
![how-to-use-mindspore-lite](figures/01.png)
The development process consists of the following main steps:
1. Prepare the required model.
The required model can be downloaded directly or obtained using the model conversion tool.
- If the downloaded model is in the `.ms` format, you can use it directly for inference. The following uses the **mobilenetv2.ms** model as an example.
- If the downloaded model uses a third-party framework, such as TensorFlow, TensorFlow Lite, Caffe, or ONNX, you can use the [model conversion tool](https://www.mindspore.cn/lite/docs/en/r1.5/use/benchmark_tool.html) to convert it to the `.ms` format.
2. Create a context, and set parameters such as the number of runtime threads and device type.
```c
// Create a context, and set the number of runtime threads to 2 and the thread affinity mode to 1 (big cores first).
OH_AI_ContextHandle context = OH_AI_ContextCreate();
if (context == NULL) {
printf("OH_AI_ContextCreate failed.\n");
return OH_AI_STATUS_LITE_ERROR;
}
const int thread_num = 2;
OH_AI_ContextSetThreadNum(context, thread_num);
OH_AI_ContextSetThreadAffinityMode(context, 1);
// Set the device type to CPU, and disable Float16 inference.
OH_AI_DeviceInfoHandle cpu_device_info = OH_AI_DeviceInfoCreate(OH_AI_DEVICETYPE_CPU);
if (cpu_device_info == NULL) {
printf("OH_AI_DeviceInfoCreate failed.\n");
OH_AI_ContextDestroy(&context);
return OH_AI_STATUS_LITE_ERROR;
}
OH_AI_DeviceInfoSetEnableFP16(cpu_device_info, false);
OH_AI_ContextAddDeviceInfo(context, cpu_device_info);
```
3. Create, load, and build the model.
Call **OH_AI_ModelBuildFromFile** to load and build the model.
In this example, the **argv[1]** parameter passed to **OH_AI_ModelBuildFromFile** indicates the specified model file path.
```c
// Create a model.
OH_AI_ModelHandle model = OH_AI_ModelCreate();
if (model == NULL) {
printf("OH_AI_ModelCreate failed.\n");
OH_AI_ContextDestroy(&context);
return OH_AI_STATUS_LITE_ERROR;
}
// Load and build the model. The model type is OH_AI_ModelTypeMindIR.
int ret = OH_AI_ModelBuildFromFile(model, argv[1], OH_AI_ModelTypeMindIR, context);
if (ret != OH_AI_STATUS_SUCCESS) {
printf("OH_AI_ModelBuildFromFile failed, ret: %d.\n", ret);
OH_AI_ModelDestroy(&model);
return ret;
}
```
4. Input data.
Before executing model inference, you need to populate data to the input tensor. In this example, random data is used to populate the model.
```c
// Obtain the input tensor.
OH_AI_TensorHandleArray inputs = OH_AI_ModelGetInputs(model);
if (inputs.handle_list == NULL) {
printf("OH_AI_ModelGetInputs failed, ret: %d.\n", ret);
OH_AI_ModelDestroy(&model);
return ret;
}
// Use random data to populate the tensor.
ret = GenerateInputDataWithRandom(inputs);
if (ret != OH_AI_STATUS_SUCCESS) {
printf("GenerateInputDataWithRandom failed, ret: %d.\n", ret);
OH_AI_ModelDestroy(&model);
return ret;
}
```
5. Execute model inference.
Call **OH_AI_ModelPredict** to perform model inference.
```c
// Execute model inference.
OH_AI_TensorHandleArray outputs;
ret = OH_AI_ModelPredict(model, inputs, &outputs, NULL, NULL);
if (ret != OH_AI_STATUS_SUCCESS) {
printf("OH_AI_ModelPredict failed, ret: %d.\n", ret);
OH_AI_ModelDestroy(&model);
return ret;
}
```
6. Obtain the output.
After model inference is complete, you can obtain the inference result through the output tensor.
```c
// Obtain the output tensor and print the information.
for (size_t i = 0; i < outputs.handle_num; ++i) {
OH_AI_TensorHandle tensor = outputs.handle_list[i];
int64_t element_num = OH_AI_TensorGetElementNum(tensor);
printf("Tensor name: %s, tensor size is %zu ,elements num: %lld.\n", OH_AI_TensorGetName(tensor),
OH_AI_TensorGetDataSize(tensor), element_num);
const float *data = (const float *)OH_AI_TensorGetData(tensor);
printf("output data is:\n");
const int max_print_num = 50;
for (int j = 0; j < element_num && j <= max_print_num; ++j) {
printf("%f ", data[j]);
}
printf("\n");
}
```
7. Destroy the model.
If the MindSpore Lite inference framework is no longer needed, you need to destroy the created model.
```c
// Destroy the model.
OH_AI_ModelDestroy(&model);
```
## Verification
1. Compile **CMakeLists.txt**.
```cmake
cmake_minimum_required(VERSION 3.14)
project(Demo)
add_executable(demo main.c)
target_link_libraries(
demo
mindspore-lite.huawei
pthread
dl
)
```
- To use ohos-sdk for cross compilation, you need to set the native toolchain path for the CMake tool as follows: `-DCMAKE_TOOLCHAIN_FILE="/xxx/ohos-sdk/linux/native/build/cmake/ohos.toolchain.cmake"`.
- The toolchain builds a 64-bit application by default. To build a 32-bit application, add the following configuration: `-DOHOS_ARCH="armeabi-v7a"`.
2. Run the CMake tool.
- Use hdc_std to connect to the RK3568 development board and put **demo** and **mobilenetv2.ms** to the same directory on the board.
- Run the hdc_std shell command to access the development board, go to the directory where **demo** is located, and run the following command:
```shell
./demo mobilenetv2.ms
```
The inference is successful if the output is similar to the following:
```shell
# ./QuickStart ./mobilenetv2.ms
Tensor name: Softmax-65, tensor size is 4004 ,elements num: 1001.
output data is:
0.000018 0.000012 0.000026 0.000194 0.000156 0.001501 0.000240 0.000825 0.000016 0.000006 0.000007 0.000004 0.000004 0.000004 0.000015 0.000099 0.000011 0.000013 0.000005 0.000023 0.000004 0.000008 0.000003 0.000003 0.000008 0.000014 0.000012 0.000006 0.000019 0.000006 0.000018 0.000024 0.000010 0.000002 0.000028 0.000372 0.000010 0.000017 0.000008 0.000004 0.000007 0.000010 0.000007 0.000012 0.000005 0.000015 0.000007 0.000040 0.000004 0.000085 0.000023
```
......@@ -3,7 +3,4 @@
- [Common Event and Notification Overview](notification-brief.md)
- [Common Event Development](common-event.md)
- [Notification Development](notification-guidelines.md)
- Agent-Powered Scheduled Reminder
- [Agent-Powered Scheduled Reminder Overview](background-agent-scheduled-reminder-overview.md)
- [Agent-Powered Scheduled Reminder Development](background-agent-scheduled-reminder-guide.md)
- [Debugging Assistant Usage](assistant-guidelines.md)
# Agent-Powered Scheduled Reminder Overview
Your application can call the **ReminderRequest** class to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background, even when your application is frozen or exits.
# Development References
- [Component Reference (TypeScript-based Declarative Development Paradigm)](arkui-ts/Readme-EN.md)
- [Component Reference (JavaScript-based Web-like Development Paradigm)](arkui-js/Readme-EN.md)
- [API Reference (JS and TS APIs)](apis/Readme-EN.md)
- API Reference (Native APIs)
- [Standard Libraries Supported by Native APIs](native-lib/Readme-EN.md)
- [SysCap List](syscap-list.md)
- [Component Reference (ArkTS-based Declarative Development Paradigm)](arkui-ts/Readme-EN.md)
- [Component Reference (JavaScript-based Web-like Development Paradigm)](arkui-js/Readme-EN.md)
- [API Reference (JS and TS APIs)](apis/Readme-EN.md)
- API Reference (Native APIs)
- [Standard Libraries Supported by Native APIs](native-lib/Readme-EN.md)
......@@ -45,6 +45,7 @@
- [@ohos.application.formInfo](js-apis-formInfo.md)
- [@ohos.application.formProvider](js-apis-formprovider.md)
- [@ohos.application.missionManager](js-apis-missionManager.md)
- [@ohos.application.quickFixManager](js-apis-application-quickFixManager.md)
- [@ohos.application.Want](js-apis-application-Want.md)
- [@ohos.continuation.continuationManager](js-apis-continuation-continuationExtraParams.md)
- [@ohos.continuation.continuationManager](js-apis-continuation-continuationManager.md)
......@@ -76,6 +77,7 @@
- bundle/[ApplicationInfo](js-apis-bundle-ApplicationInfo.md)
- bundle/[BundleInfo](js-apis-bundle-BundleInfo.md)
- bundle/[BundleInstaller](js-apis-bundle-BundleInstaller.md)
- bundle/[BundleStatusCallback](js-apis-Bundle-BundleStatusCallback.md)
- bundle/[CustomizeData](js-apis-bundle-CustomizeData.md)
- bundle/[DispatchInfo](js-apis-dispatchInfo.md)
- bundle/[ElementName](js-apis-bundle-ElementName.md)
......@@ -84,9 +86,10 @@
- bundle/[LauncherAbilityInfo](js-apis-bundle-LauncherAbilityInfo.md)
- bundle/[Metadata](js-apis-bundle-Metadata.md)
- bundle/[ModuleInfo](js-apis-bundle-ModuleInfo.md)
- bundle/[PackInfo](js-apis-bundle-PackInfo.md)
- bundle/[PermissionDef](js-apis-bundle-PermissionDef.md)
- bundle/[RemoteAbilityInfo](js-apis-bundle-remoteAbilityInfo.md)
- bundle/[ShortcutInfo<sup>(deprecated)</sup>](js-apis-bundle-ShortcutInfo.md)
- bundle/[ShortcutInfo](js-apis-bundle-ShortcutInfo.md)
- UI Page
- [@ohos.animator](js-apis-animator.md)
- [@ohos.mediaquery](js-apis-mediaquery.md)
......@@ -97,6 +100,7 @@
- [@ohos.animation.windowAnimationManager](js-apis-windowAnimationManager.md)
- [@ohos.display ](js-apis-display.md)
- [@ohos.effectKit](js-apis-effectKit.md)
- [@ohos.graphics.colorSpaceManager](js-apis-colorSpaceManager.md)
- [@ohos.screen](js-apis-screen.md)
- [@ohos.screenshot](js-apis-screenshot.md)
- [@ohos.window](js-apis-window.md)
......@@ -144,6 +148,7 @@
- [@ohos.environment](js-apis-environment.md)
- [@ohos.fileio](js-apis-fileio.md)
- [@ohos.fileManager](js-apis-filemanager.md)
- [@ohos.filemanagement.userfile_manager](js-apis-userfilemanager.md)
- [@ohos.multimedia.medialibrary](js-apis-medialibrary.md)
- [@ohos.securityLabel](js-apis-securityLabel.md)
- [@ohos.statfs](js-apis-statfs.md)
......@@ -159,8 +164,13 @@
- [@ohos.telephony.sms](js-apis-sms.md)
- Network Management
- [@ohos.net.connection](js-apis-net-connection.md)
- [@ohos.net.ethernet](js-apis-net-ethernet.md)
- [@ohos.net.http](js-apis-http.md)
- [@ohos.net.policy](js-apis-net-policy.md)
- [@ohos.net.sharing](js-apis-net-sharing.md)
- [@ohos.net.socket](js-apis-socket.md)
- [@ohos.net.statistics](js-apis-net-statistics.md)
- [@ohos.net.tlsSocket](js-apis-tlsSocket.md)
- [@ohos.net.webSocket](js-apis-webSocket.md)
- [@ohos.request](js-apis-request.md)
- Connectivity
......@@ -172,8 +182,8 @@
- [@ohos.rpc](js-apis-rpc.md)
- [@ohos.wifi](js-apis-wifi.md)
- [@ohos.wifiext](js-apis-wifiext.md)
- [@ohos.nfc.tag](js-apis-nfctech.md)
- [@ohos.nfc.tag](js-apis-tagSession.md)
- tag/[nfctech](js-apis-nfctech.md)
- tag/[tagSession](js-apis-tagSession.md)
- Basic Features
- [@ohos.accessibility](js-apis-accessibility.md)
- [@ohos.accessibility.config](js-apis-accessibility-config.md)
......@@ -185,8 +195,8 @@
- [@ohos.hiSysEvent](js-apis-hisysevent.md)
- [@ohos.hiTraceChain](js-apis-hitracechain.md)
- [@ohos.hiTraceMeter](js-apis-hitracemeter.md)
- [@ohos.inputMethod](js-apis-inputmethod.md)
- [@ohos.inputMethodEngine](js-apis-inputmethodengine.md)
- [@ohos.inputmethod](js-apis-inputmethod.md)
- [@ohos.inputmethodengine](js-apis-inputmethodengine.md)
- [@ohos.inputmethodextensionability](js-apis-inputmethod-extension-ability.md)
- [@ohos.inputmethodextensioncontext](js-apis-inputmethod-extension-context.md)
- [@ohos.pasteboard](js-apis-pasteboard.md)
......
# BundleStatusCallback
The **BundleStatusCallback** module provides bundle callback information, which is obtained through [innerBundleManager.on](js-apis-Bundle-InnerBundleManager.md).
> **NOTE**
>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## BundleStatusCallback
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.BundleManager.BundleFramework
| Name | Type | Description |
| ------ | --------------------------------------------- | -------------------------------------- |
| add | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is added.|
| update | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is updated.|
| remove | (bundleName : string, userId: number) => void | Callback invoked when a **launcherStatusCallback** is removed.|
# Color Space Management
The **colorSpaceManager** module provides APIs for creating and managing color space objects and obtaining basic color space attributes.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
```
## ColorSpace
Enumerates the color space types.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
| Name | Value | Description |
| --------------------------- | ------ | ----------------------- |
| UNKNOWN | 0 | Unknown type.|
| ADOBE_RGB_1998 | 1 | Adobe RGB (1998).|
| DCI_P3 | 2 | DCI-P3.|
| DISPLAY_P3 | 3 | Display P3.|
| SRGB | 4 | SRGB.<br>This is the default color space type.|
| CUSTOM | 5 | Custom type.|
## ColorSpacePrimaries
Defines the color space primaries. A color space is defined by chromaticity coordinates of the red, green, and blue additive primaries, the white point, and the gamma.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
| Name | Type| Readable| Writable| Description |
| ---------------------------- | -------- | ---- | ---- | ----------------------------------------------------- |
| redX | number | Yes | Yes | X coordinate of the red color in the color space.|
| redY | number | Yes | Yes | Y coordinate of the red color in the color space.|
| greenX | number | Yes | Yes | X coordinate of the green color in the color space.|
| greenY | number | Yes | Yes | Y coordinate of the green color in the color space.|
| blueX | number | Yes | Yes | X coordinate of the blue color in the color space.|
| blueY | number | Yes | Yes | Y coordinate of the blue color in the color space.|
| whitePointX | number | Yes | Yes | X coordinate of the white point in the color space.|
| whitePointY | number | Yes | Yes | Y coordinate of the white point in the color space.|
## colorSpaceManager.create
create(colorSpaceName: ColorSpace): ColorSpaceManager
Creates a standard color space object.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Parameters**
| Parameter | Type | Mandatory| Description |
| --------------- | ------------------------ | ---- | -----------------------------|
| colorSpaceName | [ColorSpace](#colorspace)| Yes | Type of the color space.<br>**UNKNOWN** and **CUSTOM** cannot be used when creating standard color space objects. |
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| [ColorSpaceManager](#colorspacemanager) | Color space object created. |
**Example**
```js
let colorSpace = null;
try {
colorSpace = colorSpaceManager.create(colorSpaceManager.ColorSpace.SRGB);
} catch (err) {
console.log(`Failed to create SRGB colorSpace. Cause: ` + JSON.stringify(err));
}
```
## colorSpaceManager.create
create(primaries: ColorSpacePrimaries, gamma: number): ColorSpaceManager
Creates a custom color space object.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Parameters**
| Parameter | Type | Mandatory| Description |
| --------------- | ------------------------------------------ | ---- | -----------------------------|
| primaries | [ColorSpacePrimaries](#colorspaceprimaries)| Yes | Primaries of the color space. |
| gamma | number | Yes | Gamma of the color space. |
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| [ColorSpaceManager](#colorspacemanager) | Color space object created.<br>The color space type is **CUSTOM** of [ColorSpace](#colorspace).|
**Example**
```js
let colorSpace = null;
try {
let primaries = {
redX: 0.1,
redY: 0.1,
greenX: 0.2,
greenY: 0.2,
blueX: 0.3,
blueY: 0.3,
whitePointX: 0.4,
whitePointY: 0.4
};
let gamma = 2.2;
colorSpace = colorSpaceManager.create(primaries, gamma);
} catch (err) {
console.log(`Failed to create colorSpace with customized primaries and gamma. Cause: ` + JSON.stringify(err));
}
```
## ColorSpaceManager
Implements management of color space objects.
Before calling any of the following APIs, you must use [create()](#colorspacemanagercreate) to create a color space object.
### getColorSpaceName
getColorSpaceName(): ColorSpace
Obtains the color space type.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| [ColorSpace](#colorspace) | Color space type.|
**Example**
```js
try {
let csType = colorSpace.getColorSpaceName();
} catch (err) {
console.log(`Fail to get colorSpace's name. Cause: ` + JSON.stringify(err));
}
```
### getWhitePoint
getWhitePoint(): Array\<number\>
Obtains the coordinates of the white point of the color space.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| Array\<number\> | Coordinates [x, y] of the white point.|
**Example**
```js
try {
let wp = colorSpace.getWhitePoint();
} catch (err) {
console.log(`Failed to get white point. Cause: ` + JSON.stringify(err));
}
```
### getGamma
getGamma(): number
Obtains the gamma of the color space.
**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core
**Return value**
| Type | Description |
| ------------------ | ------------------------ |
| number | Gamma of the color space.|
**Example**
```js
try {
let gamma = colorSpace.getGamma();
} catch (err) {
console.log(`Failed to get gamma. Cause: ` + JSON.stringify(err));
}
```
# Ethernet Connection Management
The Ethernet Connection Management module provides wired network capabilities, which allow users to set the IP address, subnet mask, gateway, and Domain Name System (DNS) server of a wired network.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import ethernet from '@ohos.net.ethernet'
```
## ethernet.setIfaceConfig
setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback\<void>): void;
Sets the network interface configuration. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------- | ---- | ------------------------------------------ |
| iface | string | Yes | Name of the network interface. |
| ic | [InterfaceConfiguration](#interfaceconfiguration) | Yes | Network interface configuration to set. |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|
**Example**
```js
ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", routeAddr:"192.168.1.1",
gateAddr:"192.168.1.1", maskAddr:"255.255.255.0", dnsAddr0:"1.1.1.1", dnsAddr1:"2.2.2.2"},
(error) => {
if (error) {
console.log("setIfaceConfig callback error = " + error);
} else {
console.log("setIfaceConfig callback ok ");
}
});
```
## ethernet.setIfaceConfig
setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\<void>;
Sets the network interface configuration. This API uses a promise to return the result.
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------------------------------------------------- | ---- | ------------------------ |
| iface | string | Yes | Name of the network interface. |
| ic | [InterfaceConfiguration](#interfaceconfiguration) | Yes | Network interface configuration to set.|
**Return value**
| Type | Description |
| ------------------- | ----------------------------------------------------------- |
| Promise\<void> | Promise that returns no value.|
**Example**
```js
ethernet.setIfaceConfig("eth0", {mode:ethernet.STATIC,ipAddr:"192.168.1.123", routeAddr:"192.168.1.1",
gateAddr:"192.168.1.1", maskAddr:"255.255.255.0", dnsAddr0:"1.1.1.1", dnsAddr1:"2.2.2.2"}).then(() => {
console.log("setIfaceConfig promiss ok ");
}).catch((error) => {
console.log("setIfaceConfig promiss error = " + error);
});
```
## ethernet.getIfaceConfig
getIfaceConfig(iface: string, callback: AsyncCallback\<InterfaceConfiguration>): void;
Obtains the configuration of a network interface. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------------------- | ----- | ------------ |
| iface | string | Yes | Name of the network interface.|
| callback | AsyncCallback\<[InterfaceConfiguration](#interfaceconfiguration)> | Yes | Callback used to return the configuration. |
**Example**
```js
ethernet.getIfaceConfig("eth0", (error, value) => {
if (error) {
console.log("getIfaceConfig callback error = " + error);
} else {
console.log("getIfaceConfig callback mode = " + value.mode);
console.log("getIfaceConfig callback ipAddr = " + value.ipAddr);
console.log("getIfaceConfig callback routeAddr = " + value.routeAddr);
console.log("getIfaceConfig callback gateAddr = " + value.gateAddr);
console.log("getIfaceConfig callback maskAddr = " + value.maskAddr);
console.log("getIfaceConfig callback dns0Addr = " + value.dns0Addr);
console.log("getIfaceConfig callback dns1Addr = " + value.dns1Addr);
}
});
```
## ethernet.getIfaceConfig
getIfaceConfig(iface: string): Promise\<InterfaceConfiguration>;
Obtains the configuration of a network interface. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ------------ |
| iface | string | Yes | Name of the network interface.|
**Return value**
| Type | Description |
| --------------------------------- | ---------------------------------- |
| Promise\<[InterfaceConfiguration](#interfaceconfiguration)> | Promise used to return the configuration. |
**Example**
```js
ethernet.getIfaceConfig("eth0").then((data) => {
console.log("getIfaceConfig promiss mode = " + data.mode);
console.log("getIfaceConfig promiss ipAddr = " + data.ipAddr);
console.log("getIfaceConfig promiss routeAddr = " + data.routeAddr);
console.log("getIfaceConfig promiss gateAddr = " + data.gateAddr);
console.log("getIfaceConfig promiss maskAddr = " + data.maskAddr);
console.log("getIfaceConfig promiss dns0Addr = " + data.dns0Addr);
console.log("getIfaceConfig promiss dns1Addr = " + data.dns1Addr);
}).catch((error) => {
console.log("getIfaceConfig promiss error = " + error);
});
```
## ethernet.isIfaceActive
isIfaceActive(iface?: string, callback: AsyncCallback\<number>): void;
Checks whether a network interface is active. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | -------------------------------------------------- |
| iface | string | No | Name of the network interface. If this parameter is left empty, the API checks for any active network interface. |
| callback | AsyncCallback\<number> | Yes | Callback used to return the result. The value **1** means that the network interface is active, **0** means that the network interface is inactive, and any other value means that an error has occurred.|
**Example**
```js
ethernet.isIfaceActive("eth0", (error, value) => {
if (error) {
console.log("whether2Activate callback error = " + error);
} else {
console.log("whether2Activate callback = " + value);
}
});
```
## ethernet.isIfaceActive
isIfaceActive(iface?: string): Promise\<number>;
Checks whether a network interface is active. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | -------------------------------------- |
| iface | string | No | Name of the network interface. If this parameter is left empty, the API checks for any active network interface.|
**Return value**
| Type | Description |
| ----------------| ------------------------------------------------------------------ |
| Promise\<number> | Promise used to return the result. The value **1** means that the network interface is active, **0** means that the network interface is inactive, and any other value means that an error has occurred.|
**Example**
```js
ethernet.isIfaceActive("eth0").then((data) => {
console.log("isIfaceActive promiss = " + data);
}).catch((error) => {
console.log("isIfaceActive promiss error = " + error);
});
```
## ethernet.getAllActiveIfaces
getAllActiveIfaces(callback: AsyncCallback\<Array\<string>>): void;
Obtains all active network interfaces. This API uses an asynchronous callback to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------ | ---- | ------------------------------ |
| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return all the active network interface names obtained.|
**Example**
```js
ethernet.getAllActiveIfaces((error, value) => {
if (error) {
console.log("getAllActiveIfaces callback error = " + error);
} else {
console.log("getAllActiveIfaces callback value.length = " + value.length);
for (let i = 0; i < value.length; i++) {
console.log("getAllActiveIfaces callback = " + value[i]);
}
}
});
```
## ethernet.getAllActiveIfaces
getAllActiveIfaces(): Promise\<Array\<string>>;
Obtains all active network interfaces. This API uses a promise to return the result.
**Required permission**: ohos.permission.GET_NETWORK_INFO
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
**Return value**
| Type | Description |
| ------------------------------ | ----------------------------------------------- |
| Promise\<Array\<string>> | Promise used to return all the active network interface names obtained.|
**Example**
```js
ethernet.getAllActiveIfaces().then((data) => {
console.log("getAllActiveIfaces promiss data.length = " + data.length);
for (let i = 0; i < data.length; i++) {
console.log("getAllActiveIfaces promiss = " + data[i]);
}
}).catch((error) => {
console.log("getAllActiveIfaces promiss error = " + error);
});
```
## InterfaceConfiguration
Defines the network configuration for the Ethernet connection.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Description |
| ----------------------- | ----------------------------------- | ------------------------------------------------------------ |
| mode | [IPSetMode](#ipsetmode) | Configuration mode of the Ethernet connection.|
| ipAddr | string | Static IP address of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in Dynamic Host Configuration Protocol (DHCP) mode.|
| route | string | Route of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.|
| gateway | string | Gateway of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.|
| netMask | string | Subnet mask of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode.|
| dnsServers | string | DNS server addresses of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode. Multiple addresses are separated by commas (,).|
## IPSetMode
Defines the configuration mode of the Ethernet connection.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Value | Description |
| ------------------------ | ---- | ---------------------- |
| STATIC | 0 | Static configuration.|
| DHCP | 1 | Dynamic configuration.|
此差异已折叠。
# Network Traffic Management
The Network Traffic Management module collects statistics on the mobile data traffic and allows you to query the data volume by network interface (cellular or Wi-Fi) or application.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import statistics from '@ohos.net.statistics'
```
## statistics.getIfaceRxBytes
getIfaceRxBytes(nic: string, callback: AsyncCallback\<number>): void
Obtains the volume of mobile data traffic received by a specified NIC. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | Yes | NIC name.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getIfaceRxBytes(this.nic, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceRxBytes
getIfaceRxBytes(nic: string): Promise\<number>;
Obtains the volume of mobile data traffic received by a specified NIC. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | Yes | NIC name.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getIfaceRxBytes(this.nic).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceTxBytes
getIfaceTxBytes(nic: string, callback: AsyncCallback\<number>): void
Obtains the volume of mobile data traffic sent by a specified NIC. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | Yes | NIC name.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getIfaceTxBytes(this.nic, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getIfaceTxBytes
getIfaceTxBytes(nic: string): Promise\<number>;
Obtains the volume of mobile data traffic sent by a specified NIC. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| nic | string | Yes | NIC name.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getIfaceTxBytes(this.nic).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularRxBytes
getCellularRxBytes(callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic received by the cellular network. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getCellularRxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularRxBytes
getCellularRxBytes(): Promise\<number>;
Obtains the volume of mobile data traffic received by the cellular network. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getCellularRxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularTxBytes
getCellularTxBytes(callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic sent by the cellular network. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getCellularTxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getCellularTxBytes
getCellularTxBytes(): Promise\<number>;
Obtains the volume of mobile data traffic sent by the cellular network. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getCellularTxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getAllRxBytes
getAllRxBytes(callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic received by all NICs. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getAllRxBytes(err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getAllRxBytes
getAllRxBytes(): Promise\<number>;
Obtains the volume of mobile data traffic received by all NICs. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getAllRxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getAllTxBytes
getAllTxBytes(callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic sent by all NICs. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getAllTxBytes((err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getAllTxBytes
getAllTxBytes(): Promise\<number>;
Obtains the volume of mobile data traffic sent by all NICs. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getAllTxBytes().then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getUidRxBytes
getUidRxBytes(uid: number, callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic received by a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Application ID.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getUidRxBytes(this.uid, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getUidRxBytes
getUidRxBytes(uid: number): Promise\<number>;
Obtains the volume of mobile data traffic received by a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Application ID.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getUidRxBytes(this.uid).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
## statistics.getUidTxBytes
getUidTxBytes(uid: number, callback: AsyncCallback\<number>): void;
Obtains the volume of mobile data traffic sent by a specified application. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Application ID.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the data volume, in bytes.|
**Example**
```js
statistics.getUidTxBytes(this.uid, (err, data) => {
this.callBack(err, data);
console.log(JSON.stringify(error))
console.log(JSON.stringify(data))
})
```
## statistics.getUidTxBytes
getUidTxBytes(uid: number): Promise\<number>;
Obtains the volume of mobile data traffic sent by a specified application. This API uses a promise to return the result.
**System capability**: SystemCapability.Communication.NetManager.Core
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- |
| uid | number | Yes | Application ID.|
**Return value**
| Type | Description |
| --------------------------------- | ------------------------------------- |
| Promise\<number> | Promise used to return the data volume, in bytes.|
**Example**
```js
statistics.getUidTxBytes(this.uid).then((err, data) {
console.log(JSON.stringify(err))
console.log(JSON.stringify(data))
})
```
# TLSSocket
The Transport Layer Security (TLS) protocol is designed to help protect the privacy of information at the transport layer. TLSSocket is an extension to socket communication. It provides higher security than socket communication by adding a security protection layer, which consists of the following submodules: key, certificate, and communication.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import socket from '@ohos.net.tlssocket'
```
## socket.constructTLSSocketInstance
constructTLSSocketInstance(): TLSSocket
Creates a **TLSSocket** object.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Example**
```js
let tlssocket = socket.constructTLSSocketInstance();
```
## tlssocket.connect
connect(options: TLSConnectOptions, callback: AsyncCallback\<void>): void
Sets up a TLSSocket connection, and creates and initializes a TLS session. 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.
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ---------------------------------------| ----| --------------- |
| options | [TLSConnectOptions](#tlsconnectoptions) | Yes | Parameters required for the connection.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|
**Example**
```js
let options = {
ALPNProtocols: ["spdy/1", "http/1.1"],
address: {
address: "xxx",
port: "xxxx",
family: 1,
},
secureOptions: {
key: "xxxx",
cert: "xxxx",
ca: ["xxxx"],
passwd: "xxxx",
protocols: "TlsV1_2",
useRemoteCipherPrefer: true,
signatureAlgorithms: SHA256,
cipherSuites: AES256-SHA256,
},
};
tlssocket.connect(options, (err, data) => {
console.info(err);
console.info(data);
});
```
## tlssocket.connect
connect(options: TLSConnectOptions): Promise\<void>;
Sets up a TLSSocket connection, and creates and initializes a TLS session. During this process, a TLS/SSL handshake is performed between the application and the server to implement data transmission. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | --------------------------------------| ----| --------------- |
| options | [TLSConnectOptions](#tlsconnectoptions) | Yes | Parameters required for the connection.|
**Return value**
| Type | Description |
| ------------------------------------------- | ----------------------------- |
| Promise\<void> | Promise used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|
**Example**
```js
let options = {
ALPNProtocols: ["spdy/1", "http/1.1"],
address: {
address: "xxxx",
port: "xxxx",
family: 1,
},
secureOptions: {
key: "xxxx",
cert: "xxxx",
ca: ["xxxx"],
passwd: "xxxx",
protocols: "TlsV1_2",
useRemoteCipherPrefer: true,
signatureAlgorithms: SHA256,
cipherSuites: AES256-SHA256,
},
};
tlssocket.connect(options).then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getCertificate
getCertificate(callback: AsyncCallback\<string>): void;
Obtains the local digital certificate after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | Yes | Callback used to return the result.|
**Example**
```js
tlssocket.getCertificate((err, data) => {
if (err) {
console.log("getCertificate callback error = " + err);
} else {
console.log("getCertificate callback = " + data);
}
});
```
## tlssocket.getCertificate
getCertificate():Promise\<string>;
Obtains the local digital certificate after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| -------------- | -------------------- |
| Promise\<string> | Promise used to return the result.|
**Example**
```js
tlssocket.getCertificate().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getRemoteCertificate
getRemoteCertificate(callback: AsyncCallback\<string>): void;
Obtains the remote digital certificate after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | Yes | Callback used to return the result.|
**Example**
```js
tlssocket.getRemoteCertificate((err, data) => {
if (err) {
console.log("getRemoteCertificate callback error = " + err);
} else {
console.log("getRemoteCertificate callback = " + data);
}
});
```
## tlssocket.getRemoteCertificate
getRemoteCertificate():Promise\<string>;
Obtains the remote digital certificate after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| -------------- | -------------------- |
| Promise\<string> | Promise used to return the result.|
**Example**
```js
tlssocket.getRemoteCertificate().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getProtocol
getProtocol(callback: AsyncCallback\<string>): void;
Obtains the communication protocol after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<string> | Yes | Callback used to return the result. |
**Example**
```js
tlssocket.getProtocol((err, data) => {
if (err) {
console.log("getProtocol callback error = " + err);
} else {
console.log("getProtocol callback = " + data);
}
});
```
## tlssocket.getProtocol
getProtocol():Promise\<string>;
Obtains the communication protocol after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| -------------- | -------------------- |
| Promise\<string> | Promise used to return the result.|
**Example**
```js
tlssocket.getProtocol().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getCipherSuites
getCipherSuites(callback: AsyncCallback\<Array\<string>>): void;
Obtains the cipher suites supported by both parties after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description|
| -------- | ----------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return the result. |
**Example**
```js
tlssocket.getCipherSuites((err, data) => {
if (err) {
console.log("getCipherSuites callback error = " + err);
} else {
console.log("getCipherSuites callback = " + data);
}
});
```
## tlssocket.getCipherSuites
getCipherSuites(): Promise\<Array\<string>>;
Obtains the cipher suites supported by both parties after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| ---------------------- | --------------------- |
| Promise\<Array\<string>> | Promise used to return the result.|
**Example**
```js
tlssocket.getCipherSuites().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.getSignatureAlgorithms
getSignatureAlgorithms(callback: AsyncCallback\<Array\<string>>): void;
Obtains the signing algorithms supported by both parties after a TLSSocket connection is established. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------------| ---- | ---------------|
| callback | AsyncCallback\<Array\<string>> | Yes | Callback used to return the result. |
**Example**
```js
tlssocket.getSignatureAlgorithms((err, data) => {
if (err) {
console.log("getSignatureAlgorithms callback error = " + err);
} else {
console.log("getSignatureAlgorithms callback = " + data);
}
});
```
## tlssocket.getSignatureAlgorithms
getSignatureAlgorithms(): Promise\<Array\<string>>;
Obtains the signing algorithms supported by both parties after a TLSSocket connection is established. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| ---------------------- | -------------------- |
| Promise\<Array\<string>> | Promise used to return the result.|
**Example**
```js
tlssocket.getSignatureAlgorithms().then(data => {
console.info(data);
}).catch(err => {
console.error(err);
});
```
## tlssocket.close
close(callback: AsyncCallback\<void>): void;
Closes a TLSSocket connection. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -----------------------------| ---- | ---------------|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
```js
tlssocket.close((err) => {
if (err) {
console.log("close callback error = " + err);
} else {
console.log("close success");
}
});
```
## tlssocket.close
close(): Promise\<void>;
Closes a TLSSocket connection. This API uses a promise to return the result.
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
| -------------- | -------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
tlssocket.close().then(() =>
console.log("close success");
}).catch(err => {
console.error(err);
});
```
## TLSConnectOptions
Defines a TLSSocket connection.
**System capability**: SystemCapability.Communication.NetStack
| Name | Type | Description |
| -------------- | ------------------------------------- | -------------- |
| address | [NetAddress](#netaddress) | Gateway address. |
| secureOptions | [TLSSecureOptions](#tlssecureoptions) | TLS security options.|
| ALPNProtocols | Array\<string> | Application Layer Protocol Negotiation (ALPN) protocols. |
## NetAddress
Defines a network address.
**System capability**: SystemCapability.Communication.NetStack
| Name | Type | Description |
| ------- | ------ | ---------------------------- |
| address | string | Network address. |
| family | number | Address family identifier. The value is **1** for IPv4 and **2** for IPv6. The default value is **1**.|
| port | number | Port number. The value ranges from **0** to **65535**. |
## TLSSecureOptions
Defines TLS security options.
**System capability**: SystemCapability.Communication.NetStack
| Name | Type | Description |
| --------------------- | ---------------------- | ---------------------- |
| ca | string \| Array\<string> | CA certificate. |
| cert | string | Local digital certificate. |
| key | string | Private key of the local digital certificate. |
| passwd | string | Password. |
| protocols | string | Protocols. |
| useRemoteCipherPrefer | boolean | Whether to use the remote cipher suite preferentially.|
| signatureAlgorithms | string | Signing algorithms. |
| cipherSuites | string | Cipher suites. |
此差异已折叠。
# Task Management
- Background Task Management
- [Background Task Management Overview](background-task-overview.md)
- [Background Task Management Development](background-task-dev-guide.md)
- Work Scheduler
- [Work Scheduler Overview](work-scheduler-overview.md)
- [Work Scheduler Development](work-scheduler-dev-guide.md)
- Agent-Powered Scheduled Reminder
- [Agent-Powered Scheduled Reminder Overview](background-agent-scheduled-reminder-overview.md)
- [Agent-Powered Scheduled Reminder Development](background-agent-scheduled-reminder-guide.md)
\ No newline at end of file
# Agent-Powered Scheduled Reminder Overview
Your application can call the **ReminderRequest** class to create scheduled reminders for countdown timers, calendar events, and alarm clocks. When the created reminders are published, the timing and pop-up notification functions of your application will be taken over by the reminder agent in the background, even when your application is frozen or exits.
......@@ -4,9 +4,10 @@
- Quick Start
- Getting Started
- [Preparations](quick-start/start-overview.md)
- [Getting Started with eTS in Stage Model](quick-start/start-with-ets-stage.md)
- [Getting Started with eTS in FA Model](quick-start/start-with-ets-fa.md)
- [Getting Started with ArkTS in Stage Model](quick-start/start-with-ets-stage.md)
- [Getting Started with ArkTS in FA Model](quick-start/start-with-ets-fa.md)
- [Getting Started with JavaScript in FA Model](quick-start/start-with-js-fa.md)
- Development Fundamentals
- [Application Package Structure Configuration File (FA Model)](quick-start/package-structure.md)
- [Application Package Structure Configuration File (Stage Model)](quick-start/stage-structure.md)
......@@ -175,6 +176,7 @@
- Access Control
- [Access Control Overview](security/accesstoken-overview.md)
- [Access Control Development](security/accesstoken-guidelines.md)
- [Permission Verification Guide](security/permission-verify-guidelines.md)
- [Permission List](security/permission-list.md)
- User Authentication
- [User Authentication Overview](security/userauth-overview.md)
......@@ -222,6 +224,9 @@
- Work Scheduler
- [Work Scheduler Overview](task-management/work-scheduler-overview.md)
- [Work Scheduler Development](task-management/work-scheduler-dev-guide.md)
- Agent-Powered Scheduled Reminder
- [Agent-Powered Scheduled Reminder Overview](task-management/background-agent-scheduled-reminder-overview.md)
- [Agent-Powered Scheduled Reminder Development](task-management/background-agent-scheduled-reminder-guide.md)
- Device
- USB Service
- [USB Service Overview](device/usb-overview.md)
......@@ -258,12 +263,14 @@
- [Internationalization Overview](internationalization/international-overview.md)
- [Internationalization Development (intl)](internationalization/intl-guidelines.md)
- [Internationalization Development (i18n)](internationalization/i18n-guidelines.md)
- [OpenHarmony IDL Specifications and User Guide](IDL/idl-guidelines.md)
- Native APIs
- [Using Native APIs in Application Projects](napi/napi-guidelines.md)
- [Drawing Development](napi/drawing-guidelines.md)
- [Raw File Development](napi/rawfile-guidelines.md)
- [Native Window Development](napi/native-window-guidelines.md)
- [Using MindSpore Lite for Model Inference](napi/mindspore-lite-guidelines.md)
- Tools
- [DevEco Studio (OpenHarmony) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- Hands-On Tutorials
......@@ -430,6 +437,7 @@
- [Time Picker Dialog Box](reference/arkui-ts/ts-methods-timepicker-dialog.md)
- [Text Picker Dialog Box](reference/arkui-ts/ts-methods-textpicker-dialog.md)
- [Menu](reference/arkui-ts/ts-methods-menu.md)
- [Pixel Units](reference/arkui-ts/ts-pixel-units.md)
- [Built-in Enums](reference/arkui-ts/ts-appendix-enums.md)
- [Types](reference/arkui-ts/ts-types.md)
- Component Reference (JavaScript-compatible Web-like Development Paradigm)
......@@ -580,6 +588,7 @@
- [@ohos.application.formInfo](reference/apis/js-apis-formInfo.md)
- [@ohos.application.formProvider](reference/apis/js-apis-formprovider.md)
- [@ohos.application.missionManager](reference/apis/js-apis-missionManager.md)
- [@ohos.application.quickFixManager](reference/apis/js-apis-application-quickFixManager.md)
- [@ohos.application.Want](reference/apis/js-apis-application-Want.md)
- [@ohos.continuation.continuationManager](reference/apis/js-apis-continuation-continuationExtraParams.md)
- [@ohos.continuation.continuationManager](reference/apis/js-apis-continuation-continuationManager.md)
......@@ -611,6 +620,7 @@
- [ApplicationInfo](reference/apis/js-apis-bundle-ApplicationInfo.md)
- [BundleInfo](reference/apis/js-apis-bundle-BundleInfo.md)
- [BundleInstaller](reference/apis/js-apis-bundle-BundleInstaller.md)
- [BundleStatusCallback](reference/apis/js-apis-Bundle-BundleStatusCallback.md)
- [CustomizeData](reference/apis/js-apis-bundle-CustomizeData.md)
- [DispatchInfo](reference/apis/js-apis-dispatchInfo.md)
- [ElementName](reference/apis/js-apis-bundle-ElementName.md)
......@@ -619,6 +629,7 @@
- [LauncherAbilityInfo](reference/apis/js-apis-bundle-LauncherAbilityInfo.md)
- [Metadata](reference/apis/js-apis-bundle-Metadata.md)
- [ModuleInfo](reference/apis/js-apis-bundle-ModuleInfo.md)
- [PackInfo](reference/apis/js-apis-bundle-PackInfo.md)
- [PermissionDef](reference/apis/js-apis-bundle-PermissionDef.md)
- [RemoteAbilityInfo](reference/apis/js-apis-bundle-remoteAbilityInfo.md)
- [ShortcutInfo](reference/apis/js-apis-bundle-ShortcutInfo.md)
......@@ -632,6 +643,7 @@
- [@ohos.animation.windowAnimationManager](reference/apis/js-apis-windowAnimationManager.md)
- [@ohos.display](reference/apis/js-apis-display.md)
- [@ohos.effectKit](reference/apis/js-apis-effectKit.md)
- [@ohos.graphics.colorSpaceManager](reference/apis/js-apis-colorSpaceManager.md)
- [@ohos.screen](reference/apis/js-apis-screen.md)
- [@ohos.screenshot](reference/apis/js-apis-screenshot.md)
- [@ohos.window](reference/apis/js-apis-window.md)
......@@ -679,6 +691,7 @@
- [@ohos.environment](reference/apis/js-apis-environment.md)
- [@ohos.fileio](reference/apis/js-apis-fileio.md)
- [@ohos.fileManager](reference/apis/js-apis-filemanager.md)
- [@ohos.filemanagement.userfile_manager](reference/apis/js-apis-userfilemanager.md)
- [@ohos.multimedia.medialibrary](reference/apis/js-apis-medialibrary.md)
- [@ohos.securityLabel](reference/apis/js-apis-securityLabel.md)
- [@ohos.statfs](reference/apis/js-apis-statfs.md)
......@@ -694,8 +707,13 @@
- [@ohos.telephony.sms](reference/apis/js-apis-sms.md)
- Network Management
- [@ohos.net.connection](reference/apis/js-apis-net-connection.md)
- [@ohos.net.ethernet](reference/apis/js-apis-net-ethernet.md)
- [@ohos.net.http](reference/apis/js-apis-http.md)
- [@ohos.net.policy](reference/apis/js-apis-net-policy.md)
- [@ohos.net.sharing](reference/apis/js-apis-net-sharing.md)
- [@ohos.net.socket](reference/apis/js-apis-socket.md)
- [@ohos.net.statistics](reference/apis/js-apis-net-statistics.md)
- [@ohos.net.tlsSocket](reference/apis/js-apis-tlsSocket.md)
- [@ohos.net.webSocket](reference/apis/js-apis-webSocket.md)
- [@ohos.request](reference/apis/js-apis-request.md)
- Connectivity
......@@ -822,7 +840,7 @@
- [Guide to Switching to Full SDK](quick-start/full-sdk-switch-guide.md)
- [Ability Framework Development](faqs/faqs-ability.md)
- [ArkUI (JavaScript) Development](faqs/faqs-ui-js.md)
- [ArkUI (eTS) Development](faqs/faqs-ui-ets.md)
- [ArkUI (ArkTS) Development](faqs/faqs-ui-ets.md)
- [Graphics and Image Development](faqs/faqs-graphics.md)
- [File Management Development](faqs/faqs-file-management.md)
- [Network and Connection Development](faqs/faqs-connectivity.md)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册