diff --git a/en/application-dev/ai/Readme-EN.md b/en/application-dev/ai/Readme-EN.md new file mode 100644 index 0000000000000000000000000000000000000000..525a9f3afe7e1e951d2216160cc23ba4c9b3335b --- /dev/null +++ b/en/application-dev/ai/Readme-EN.md @@ -0,0 +1,3 @@ +# AI + +- [Using MindSpore Lite for Model Inference (JS)](mindspore-lite-js-guidelines.md) diff --git a/en/application-dev/ai/mindspore-lite-js-guidelines.md b/en/application-dev/ai/mindspore-lite-js-guidelines.md new file mode 100644 index 0000000000000000000000000000000000000000..1f309acf19ba608ac698892ed64bb2e75ffdc437 --- /dev/null +++ b/en/application-dev/ai/mindspore-lite-js-guidelines.md @@ -0,0 +1,122 @@ +# Using MindSpore Lite for Model Inference (JS) + +## Scenarios + +MindSpore Lite is an AI engine that implements AI model inference for different hardware devices. It has been used in a wide range of fields, such as image classification, target recognition, facial recognition, and character recognition. + +This document describes the general development process for implementing MindSpore Lite model inference. For details about how to use native APIs to implement model inference, see [Using MindSpore Lite for Model Inference](../napi/mindspore-lite-guidelines.md). + +## 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 basic data structure used in MindSpore Lite network operations. + +**Float16 inference mode**: a mode that uses half-precision inference. Float16 uses 16 bits to represent a number and therefore it is also called half-precision. + +## Available APIs +APIs involved in MindSpore Lite model inference are categorized into context APIs, model APIs, and tensor APIs. For more APIs, see [@ohos.ai.mindSporeLite](../reference/apis/js-apis-mindSporeLite.md). + +| API | Description | +| ------------------ | ----------------- | +|loadModelFromFile(model: string, options: Context): Promise<Model>|Loads a model from a file.| +|getInputs(): MSTensor[]|Obtains the model input.| +|predict(inputs: MSTensor[]): Promise<MSTensor>|Performs model inference.| +| getData(): ArrayBuffer | Obtains tensor data.| +| setData(inputArray: ArrayBuffer): void | Sets the tensor data.| + +## How to Develop + +The development process consists of the following main steps: + +1. Prepare the required model. You can download the required model directly or obtain the model by using the model conversion tool. The required data is read from the `bin` file. + + - If the downloaded model is in the `.ms` format, you can use it directly for inference. This document uses `mnet.caffemodel.ms` 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/r2.0/use/downloads.html#1-8-1) to convert it to the `.ms` format. +2. Create a context, and set parameters such as the number of runtime threads and device type. +3. Load the model. In this example, the model is read from the file. +4. Load data. Before executing a model, you need to obtain the model input and then fill data in the input tensor. +5. Perform inference and print the output. Call the **predict** API to perform model inference. +```js +@State inputName: string = 'mnet_caffemodel_nhwc.bin'; +@State T_model_predict: string = 'Test_MSLiteModel_predict' +inputBuffer: any = null; +build() { + Row() { + Column() { + Text(this.T_model_predict) + .focusable(true) + .fontSize(30) + .fontWeight(FontWeight.Bold) + .onClick(async () => { + // 1. Prepare for a model. + let syscontext = globalThis.context; + syscontext.resourceManager.getRawFileContent(this.inputName).then((buffer) => { + this.inputBuffer = buffer; + console.log('=========input bin byte length: ' + this.inputBuffer.byteLength) + }).catch(error => { + console.error('Failed to get buffer, error code: ${error.code},message:${error.message}.'); + }) + // 2. Create a context. + let context: mindSporeLite.Context = {}; + context.target = ['cpu']; + context.cpu = {} + context.cpu.threadNum = 1; + context.cpu.threadAffinityMode = 0; + context.cpu.precisionMode = 'enforce_fp32'; + // 3. Load the model. + let modelFile = '/data/storage/el2/base/haps/entry/files/mnet.caffemodel.ms'; + let msLiteModel = await mindSporeLite.loadModelFromFile(modelFile, context); + // 4. Load data. + const modelInputs = msLiteModel.getInputs(); + modelInputs[0].setData(this.inputBuffer.buffer); + // 5. Perform inference and print the output. + console.log('=========MSLITE predict start=====') + msLiteModel.predict(modelInputs).then((modelOutputs) => { + let output0 = new Float32Array(modelOutputs[0].getData()); + for (let i = 0; i < output0.length; i++) { + console.log(output0[i].toString()); + } + }) + console.log('=========MSLITE predict success=====') + }) + } + .width('100%') + } + .height('100%') +} +``` + +## Debugging and Verification + +1. Connect to the rk3568 development board on DevEco Studio, click **Run entry**, and compile your own HAP. The following information is displayed: + + ```shell + Launching com.example.myapptfjs + $ hdc uninstall com.example.myapptfjs + $ hdc install -r "D:\TVOS\JSAPI\MyAppTfjs\entry\build\default\outputs\default\entry-default-signed.hap" + $ hdc shell aa start -a EntryAbility -b com.example.myapptfjs + ``` + +2. Use the hdc tool to connect to the rk3568 development board and push `mnet.caffemodel.ms` to the sandbox directory on the device. `mnet\_caffemodel\_nhwc.bin` is stored in the `rawfile` directory of the local project. + + ```shell + hdc -t 7001005458323933328a00bcdf423800 file send .\mnet.caffemodel.ms /data/app/el2/100/base/com.example.myapptfjs/haps/entry/files/ + ``` +3. Click **Test\_MSLiteModel\_predict** on the screen of the rk3568 development board to run the test case. The following information is displayed in the HiLog printing result: + + ```shell + 08-27 23:25:50.278 31782-31782/? I C03d00/JSAPP: =========MSLITE predict start===== + 08-27 23:25:51.487 31782-31782/? I C03d00/JSAPP: 0.10046602040529252 + 08-27 23:25:51.487 31782-31782/? I C03d00/JSAPP: 0.07535600662231445 + 08-27 23:25:51.487 31782-31782/? I C03d00/JSAPP: 0.06326554715633392 + 08-27 23:25:51.487 31782-31782/? I C03d00/JSAPP: 0.0015114173293113708 + 08-27 23:25:51.487 31782-31782/? I C03d00/JSAPP: -0.026745859533548355 + 08-27 23:25:51.487 31782-31782/? I C03d00/JSAPP: -0.055590517818927765 + 08-27 23:25:51.487 31782-31782/? I C03d00/JSAPP: -0.05325715243816376 + 08-27 23:25:51.487 31782-31782/? I C03d00/JSAPP: -0.04629542678594589 + ... + 08-27 23:25:52.881 31782-31782/? I C03d00/JSAPP: 0.23317644000053404 + 08-27 23:25:52.881 31782-31782/? I C03d00/JSAPP: 0.17999525368213654 + 08-27 23:25:50.372 31782-31782/? I C03d00/JSAPP: =========MSLITE predict success===== + ``` diff --git a/en/application-dev/dfx/Readme-EN.md b/en/application-dev/dfx/Readme-EN.md index b5990650c61eae7ed57a0b1dbc35489947de8bc8..977812697f34817f07a996e3d3f787c985baf840 100644 --- a/en/application-dev/dfx/Readme-EN.md +++ b/en/application-dev/dfx/Readme-EN.md @@ -4,6 +4,7 @@ - [Development of Performance Tracing](hitracemeter-guidelines.md) - [Development of Distributed Call Chain Tracing](hitracechain-guidelines.md) - [HiLog Development (Native)](hilog-guidelines.md) +- [Development of Performance Tracing (Native)](hitracemeter-native-guidelines.md) - Error Management - [Development of Error Manager](errormanager-guidelines.md) - [Development of Application Recovery](apprecovery-guidelines.md) diff --git a/en/application-dev/dfx/hitracemeter-native-guidelines.md b/en/application-dev/dfx/hitracemeter-native-guidelines.md new file mode 100644 index 0000000000000000000000000000000000000000..bb0274f7c4077b016061430250e7a949cf826864 --- /dev/null +++ b/en/application-dev/dfx/hitracemeter-native-guidelines.md @@ -0,0 +1,52 @@ +# Development of Performance Tracing (Native) + +## Introduction + +hiTraceMeter provides APIs for system performance tracing. You can call the APIs provided by the hiTraceMeter module in your own service logic to effectively track service processes and check the system performance. +> **NOTE** + +> - This development guide is applicable only when you use Native APIs for application development. For details about APIs, see [API Reference](../reference/native-apis/_hitrace.md). +> - For details about how to use ArkTS APIs for application development, see [Development Guidelines](hitracemeter-guidelines.md) and [API Reference](../reference/apis/js-apis-hitracemeter.md). + +## Available APIs + +| API| Description| +| -------- | -------- | +| void OH_HiTrace_StartTrace(const char* name) | Starts a synchronous time slice trace.| +| void OH_HiTrace_FinishTrace() | Ends a synchronous time slice trace.| +| void OH_HiTrace_StartAsyncTrace(const char* name, int32_t taskId) | Starts an asynchronous time slice trace.| +| void OH_HiTrace_FinishAsyncTrace(const char* name, int32_t taskId) | Ends an asynchronous time slice trace.| +| void OH_HiTrace_CountTrace(const char* name, int64_t count) | Performs an integer trace.| + +**Parameter Description** + +| Name| Type| Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| name | string | No | Name of the variable.| +| taskId | number | No | ID used to indicate the association of APIs in a trace. If multiple traces with the same name need to be performed at the same time or a trace needs to be performed multiple times concurrently, different task IDs must be specified in **startTrace**.| +| count | number | No | Value of the variable. | + +## Development Example + +1. Add the link of **libhitrace_ndk.z.so** to **CMakeLists.txt**. + ``` + target_link_libraries(entry PUBLIC libhitrace_ndk.z.so) + ``` +2. Reference the **hitrace** header file in the source file. + ```c++ + #include "hitrace/trace.h" + ``` +3. Open the hdc shell and run the **hitrace --trace_begin app** command to enable the trace function. + ```shell + capturing trace... + ``` +4. Perform a performance trace. The following uses asynchronous trace as an example. + ```c++ + OH_HiTrace_StartAsyncTrace("hitraceTest", 123); + OH_HiTrace_FinishAsyncTrace("hitraceTest", 123); + ``` +5. Run the **hitrace --trace_dump | grep hitraceTest** command to view the trace result. + ```shell + <...>-2477 (-------) [001] .... 396.427165: tracing_mark_write: S|2477|H:hitraceTest 123 + <...>-2477 (-------) [001] .... 396.427196: tracing_mark_write: F|2477|H:hitraceTest 123 + ``` diff --git a/en/application-dev/napi/mindspore-lite-guidelines.md b/en/application-dev/napi/mindspore-lite-guidelines.md index 8dd76e32683a9a8fd6369cb4f4f53863c4e85607..e175c3750b7c0f445f570b742073e67824726537 100644 --- a/en/application-dev/napi/mindspore-lite-guidelines.md +++ b/en/application-dev/napi/mindspore-lite-guidelines.md @@ -85,7 +85,7 @@ The development process consists of the following main steps: 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/zh-CN/r1.5/use/downloads.html#id1) to convert it to the .ms format. + - 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/downloads.html#id1) to convert it to the .ms format. 2. Create a context, and set parameters such as the number of runtime threads and device type. @@ -280,7 +280,3 @@ The development process consists of the following main steps: 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 ``` - -## Samples -The following sample is provided to help you better understand how to use MindSpore Lite: -- [Simple MindSpore Lite Tutorial](https://gitee.com/openharmony/third_party_mindspore/tree/OpenHarmony-3.2-Release/mindspore/lite/examples/quick_start_c) diff --git a/en/application-dev/reference/apis/figures/Cursor_Circle.png b/en/application-dev/reference/apis/figures/Cursor_Circle.png new file mode 100644 index 0000000000000000000000000000000000000000..75b942a03da161b31d717fcfcb0a6ede1d65e76b Binary files /dev/null and b/en/application-dev/reference/apis/figures/Cursor_Circle.png differ diff --git a/en/application-dev/reference/apis/figures/Cursor_Cross.png b/en/application-dev/reference/apis/figures/Cursor_Cross.png new file mode 100644 index 0000000000000000000000000000000000000000..1b8391c4dc617e07270489643c03eede068882d1 Binary files /dev/null and b/en/application-dev/reference/apis/figures/Cursor_Cross.png differ diff --git a/en/application-dev/reference/apis/figures/Horizontal_Text_Cursor.png b/en/application-dev/reference/apis/figures/Horizontal_Text_Cursor.png new file mode 100644 index 0000000000000000000000000000000000000000..6911b3a2c702613239bef39a7101832f5343ccdb Binary files /dev/null and b/en/application-dev/reference/apis/figures/Horizontal_Text_Cursor.png differ diff --git a/en/application-dev/reference/apis/js-apis-pointer.md b/en/application-dev/reference/apis/js-apis-pointer.md index 61bac1ec1ef7b02115705e7e5e34b600faedca60..9f949c10e762e34ae641d648d676f0d754c9b52c 100644 --- a/en/application-dev/reference/apis/js-apis-pointer.md +++ b/en/application-dev/reference/apis/js-apis-pointer.md @@ -850,3 +850,879 @@ Enumerates mouse pointer styles. | MIDDLE_BTN_SOUTH_EAST | 36 | Scrolling south-east |![MID_Btn_South_East.png](./figures/MID_Btn_South_East.png)| | MIDDLE_BTN_SOUTH_WEST | 37 | Scrolling south-west |![MID_Btn_South_West.png](./figures/MID_Btn_South_West.png)| | MIDDLE_BTN_NORTH_SOUTH_WEST_EAST | 38 | Moving as a cone in four directions|![MID_Btn_North_South_West_East.png](./figures/MID_Btn_North_South_West_East.png)| +| HORIZONTAL_TEXT_CURSOR10+ | 39 | Horizontal text selection|![Horizontal_Text_Cursor.png](./figures/Horizontal_Text_Cursor.png)| +| CURSOR_CROSS10+ | 40 | Cross cursor|![Cursor_Cross.png](./figures/Cursor_Cross.png)| +| CURSOR_CIRCLE10+ | 41 | Circular cursor|![Cursor_Circle.png](./figures/Cursor_Circle.png)| + +## pointer.setTouchpadScrollSwitch10+ + +setTouchpadScrollSwitch(state: boolean, callback: AsyncCallback\): void + +Sets the scroll switch of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| state | boolean | Yes | Scroll switch status. The value **true** indicates that the scroll switch is enabled, and the value **false** indicates the opposite. The default value is **true**. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadScrollSwitch(true, (error) => { + if (error) { + console.log(`setTouchpadScrollSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setTouchpadScrollSwitch success`); + }); +} catch (error) { + console.log(`setTouchpadScrollSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadScrollSwitch10+ + +setTouchpadScrollSwitch(state: boolean): Promise\ + +Sets the scroll switch of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| state | boolean| Yes | Scroll switch status. The value **true** indicates that the scroll switch is enabled, and the value **false** indicates the opposite. The default value is **true**.| + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadScrollSwitch(false).then(() => { + console.log(`setTouchpadScrollSwitch success`); + }); +} catch (error) { + console.log(`setTouchpadScrollSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadScrollSwitch10+ + +getTouchpadScrollSwitch(callback: AsyncCallback\): void + +Obtains the scroll switch status of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadScrollSwitch ((error, state) => { + console.log(`getTouchpadScrollSwitch success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadScrollSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadScrollSwitch10+ + +getTouchpadScrollSwitch(): Promise\ + +Obtains the scroll switch status of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadScrollSwitch().then((state) => { + console.log(`getTouchpadScrollSwitch success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadScrollSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadScrollDirection10+ + +setTouchpadScrollDirection(state: boolean, callback: AsyncCallback\): void + +Sets the scroll direction of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| state | boolean | Yes | Scroll direction of the touchpad. The value **true** indicates that the scroll direction is the same as the finger moving direction, and the value **false** indicates the opposite. The default value is **true**. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadScrollDirection(true, (error) => { + if (error) { + console.log(`setTouchpadScrollDirection failed, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setTouchpadScrollDirection success`); + }); +} catch (error) { + console.log(`setTouchpadScrollDirection failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadScrollDirection10+ + +setTouchpadScrollDirection(state: boolean): Promise\ + +Sets the scroll direction of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| state | boolean| Yes | Scroll direction of the touchpad. The value **true** indicates that the scroll direction is the same as the finger moving direction, and the value **false** indicates the opposite. The default value is **true**. | + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadScrollDirection (false).then(() => { + console.log(`setTouchpadScrollDirection success`); + }); +} catch (error) { + console.log(`setTouchpadScrollDirection failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadScrollDirection10+ + +getTouchpadScrollDirection(callback: AsyncCallback\): void + +Obtains the scroll direction of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadScrollSwitch ((error, state) => { + console.log(`getTouchpadScrollDirection success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadScrollDirection failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadScrollDirection10+ + +getTouchpadScrollDirection(): Promise\ + +Obtains the scroll direction of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadScrollDirection().then((state) => { + console.log(`getTouchpadScrollDirection success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadScrollDirection failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadTapSwitch10+ + +setTouchpadTapSwitch(state: boolean, callback: AsyncCallback\): void + +Sets the tap switch of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| state | boolean | Yes |Tap switch status of the touchpad The value **true** indicates that the tap switch is enabled, and the value **false** indicates the opposite. The default value is **true**. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadTapSwitch(true, (error) => { + if (error) { + console.log(`setTouchpadTapSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setTouchpadTapSwitch success`); + }); +} catch (error) { + console.log(`setTouchpadTapSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadTapSwitch 10+ + +setTouchpadTapSwitch(state: boolean): Promise\ + +Sets the tap switch of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| state | boolean| Yes | Tap switch status of the touchpad The value **true** indicates that the tap switch is enabled, and the value **false** indicates the opposite. The default value is **true**. | + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadTapSwitch(false).then(() => { + console.log(`setTouchpadTapSwitch success`); + }); +} catch (error) { + console.log(`setTouchpadTapSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadTapSwitch10+ + +getTouchpadTapSwitch(callback: AsyncCallback\): void + +Obtains the tap switch status of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadTapSwitch((error, state) => { + console.log(`getTouchpadTapSwitch success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadTapSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadTapSwitch10+ + +getTouchpadTapSwitch(): Promise\ + +Obtains the tap switch status of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadTapSwitch().then((state) => { + console.log(`getTouchpadTapSwitch success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadTapSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadPointerSpeed10+ + +setTouchpadPointerSpeed(speed: number, callback: AsyncCallback\): void + +Sets the cursor moving speed of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| speed | number | Yes |Cursor moving speed of the touchpad. The value range is [1,11]. The default value is **5**. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadPointerSpeed(1, (error) => { + if (error) { + console.log(`setTouchpadPointerSpeedfailed, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setTouchpadPointerSpeed success`); + }); +} catch (error) { + console.log(`setTouchpadPointerSpeed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadPointerSpeed10+ + +setTouchpadPointerSpeed(speed: number): Promise\ + +Sets the cursor moving speed of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| speed| number | Yes | Cursor moving speed of the touchpad. The value range is [1,11]. The default value is **5**. | + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadPointerSpeed(10).then(() => { + console.log(`setTouchpadPointerSpeed success`); + }); +} catch (error) { + console.log(`setTouchpadPointerSpeed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadPointerSpeed10+ + +getTouchpadPointerSpeed(callback: AsyncCallback\): void + +Obtains the cursor moving speed of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadPointerSpeed((error, speed) => { + console.log(`getTouchpadPointerSpeed success, speed: ${JSON.stringify(speed)}`); + }); +} catch (error) { + console.log(`getTouchpadPointerSpeed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadPointerSpeed10+ + +getTouchpadPointerSpeed(): Promise\ + +Obtains the cursor moving speed of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadPointerSpeed().then((speed) => { + console.log(`getTouchpadPointerSpeed success, speed: ${JSON.stringify(speed)}`); + }); +} catch (error) { + console.log(`getTouchpadPointerSpeed failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadPinchSwitch10+ + +setTouchpadPinchSwitch(state: boolean, callback: AsyncCallback\): void + +Sets the pinch switch of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| state | boolean | Yes |Pinch switch status of the touchpad. The value **true** indicates that the pinch switch is enabled, and the value **false** indicates the opposite. The default value is **true**. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadTapSwitch(true, (error) => { + if (error) { + console.log(`setTouchpadPinchSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setTouchpadPinchSwitch success`); + }); +} catch (error) { + console.log(`setTouchpadPinchSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadPinchSwitch10+ + +setTouchpadPinchSwitch(state: boolean): Promise\ + +Sets the pinch switch of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| state | boolean| Yes | Pinch switch status of the touchpad. The value **true** indicates that the pinch switch is enabled, and the value **false** indicates the opposite. The default value is **true**. | + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadPinchSwitch(false).then(() => { + console.log(`setTouchpadPinchSwitch success`); + }); +} catch (error) { + console.log(`setTouchpadPinchSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadPinchSwitch10+ + +getTouchpadPinchSwitch(callback: AsyncCallback\): void + +Obtains the pinch switch status of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadPinchSwitch((error, state) => { + console.log(`getTouchpadPinchSwitch success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadPinchSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadPinchSwitch10+ + +getTouchpadPinchSwitch(): Promise\ + +Obtains the pinch switch status of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadPinchSwitch().then((state) => { + console.log(`getTouchpadPinchSwitch success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadPinchSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadSwipeSwitch10+ + +setTouchpadSwipeSwitch(state: boolean, callback: AsyncCallback\): void + +Sets the multi-finger swipe switch of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| state | boolean | Yes |Swipe switch status of the touchpad. The value **true** indicates that the swipe switch is enabled, and the value **false** indicates the opposite. The default value is **true**. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadSwipeSwitch(true, (error) => { + if (error) { + console.log(`setTouchpadSwipeSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setTouchpadSwipeSwitch success`); + }); +} catch (error) { + console.log(`setTouchpadSwipeSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadSwipeSwitch10+ + +setTouchpadSwipeSwitch(state: boolean): Promise\ + +Sets the swipe switch of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| state | boolean| Yes | Swipe switch status of the touchpad. The value **true** indicates that the swipe switch is enabled, and the value **false** indicates the opposite. The default value is **true**. | + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadSwipeSwitch(false).then(() => { + console.log(`setTouchpadSwipeSwitch success`); + }); +} catch (error) { + console.log(`setTouchpadSwipeSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadSwipeSwitch10+ + +getTouchpadSwipeSwitch(callback: AsyncCallback\): void + +Obtains the multi-finger swipe switch status of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadSwipeSwitch((error, state) => { + console.log(`getTouchpadSwipeSwitch success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadSwipeSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadSwipeSwitch10+ + +getTouchpadSwipeSwitch(): Promise\ + +Obtains the multi-finger swipe switch status of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadSwipeSwitch().then((state) => { + console.log(`getTouchpadSwipeSwitch success, state: ${JSON.stringify(state)}`); + }); +} catch (error) { + console.log(`getTouchpadSwipeSwitch failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## RightClickType10+ + +Enumerates shortcut menu triggering modes. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +| Name | Value | Description | +| -------------------------------- | ---- | ------ | +| TOUCHPAD_RIGHT_BUTTON | 1 |Tapping the right-button area of the touchpad.| +| TOUCHPAD_LEFT_BUTTON | 2 |Tapping the left-button area of the touchpad.| +| TOUCHPAD_TWO_FINGER_TAP | 3 |Tapping or pressing the touchpad with two fingers.| + +## pointer.setTouchpadRightClickType10+ + +setTouchpadRightClickType(type: RightClickType, callback: AsyncCallback\): void + +Sets the shortcut menu type of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ------------------------- | ---- | ------------------------------------- | +| type| RightClickType| Yes |Shortcut menu type of the touchpad.
- TOUCHPAD_RIGHT_BUTTON: tapping the right-button area of the touchpad.
- TOUCHPAD_LEFT_BUTTON: tapping the left-button area of the touchpad.
- TOUCHPAD_TWO_FINGER_TAP: tapping or pressing the touchpad with two fingers.
The default value is **TOUCHPAD_RIGHT_BUTTON**. | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadRightClickType(RightClickType::TOUCHPAD_RIGHT_BUTTON , (error) => { + if (error) { + console.log(`setTouchpadRightClickType, error: ${JSON.stringify(error, [`code`, `message`])}`); + return; + } + console.log(`setTouchpadRightClickType success`); + }); +} catch (error) { + console.log(`setTouchpadRightClickType failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.setTouchpadRightClickType10+ + +setTouchpadRightClickType(type: RightClickType): Promise\ + +Sets the shortcut menu type of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----------------------------------- | +| type| RightClickType| Yes | Shortcut menu type of the touchpad.
- TOUCHPAD_RIGHT_BUTTON: tapping the right-button area of the touchpad.
- TOUCHPAD_LEFT_BUTTON: tapping the left-button area of the touchpad.
- TOUCHPAD_TWO_FINGER_TAP: tapping or pressing the touchpad with two fingers.
The default value is **TOUCHPAD_RIGHT_BUTTON**.| + +**Return value** + +| Name | Description | +| ------------------- | ---------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.setTouchpadRightClickType(RightClickType::TOUCHPAD_RIGHT_BUTTON ).then(() => { + console.log(`setTouchpadRightClickType success`); + }); +} catch (error) { + console.log(`setTouchpadRightClickType failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadRightClickType10+ + +getTouchpadRightClickType(callback: AsyncCallback\): void + +Obtains the shortcut menu type of the touchpad. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | -------------- | +| callback | AsyncCallback\ | Yes | Callback used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadRightClickType((error, type) => { + console.log(`getTouchpadRightClickType success, type: ${JSON.stringify(type)}`); + }); +} catch (error) { + console.log(`getTouchpadRightClickType failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` + +## pointer.getTouchpadRightClickType10+ + +getTouchpadRightClickType(): Promise\ + +Obtains the shortcut menu type of the touchpad. This API uses a promise to return the result. + +**System capability**: SystemCapability.MultimodalInput.Input.Pointer + +**System API**: This is a system API. + +**Return value** + +| Name | Description | +| --------------------- | ------------------- | +| Promise\ | Promise used to return the result.| + +**Example** + +```js +try { + pointer.getTouchpadRightClickType().then((type) => { + console.log(`getTouchpadRightClickType success, typeed: ${JSON.stringify(type)}`); + }); +} catch (error) { + console.log(`getTouchpadRightClickType failed, error: ${JSON.stringify(error, [`code`, `message`])}`); +} +``` diff --git a/en/application-dev/reference/apis/js-apis-radio.md b/en/application-dev/reference/apis/js-apis-radio.md index cd0c226e17cff6db5a3e6c51371137403adcd2a1..2050db9a62813fe6fabc01fd98cb9c0997bff43a 100644 --- a/en/application-dev/reference/apis/js-apis-radio.md +++ b/en/application-dev/reference/apis/js-apis-radio.md @@ -231,7 +231,7 @@ promise.then(data => { getNetworkSelectionMode\(slotId: number, callback: AsyncCallback\\): void -Obtains the network selection mode of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. +Obtains the network selection mode for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.Telephony.CoreService @@ -268,7 +268,7 @@ radio.getNetworkSelectionMode(slotId, (err, data) => { getNetworkSelectionMode\(slotId: number\): Promise\ -Obtains the network selection mode of the SIM card in the specified slot. This API uses a promise to return the result. +Obtains the network selection mode for the SIM card in the specified slot. This API uses a promise to return the result. **System capability**: SystemCapability.Telephony.CoreService @@ -957,7 +957,7 @@ promise.then(() => { getIMEI\(callback: AsyncCallback\\): void -Obtains the IMEI of the SIM card in a card slot. This API uses an asynchronous callback to return the result. +Obtains the IMEI for the SIM card in a card slot. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -998,7 +998,7 @@ radio.getIMEI((err, data) => { getIMEI\(slotId: number, callback: AsyncCallback\\): void -Obtains the IMEI of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. +Obtains the IMEI for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -1041,7 +1041,7 @@ radio.getIMEI(slotId, (err, data) => { getIMEI\(slotId?: number\): Promise\ -Obtains the IMEI of the SIM card in the specified slot. This API uses a promise to return the result. +Obtains the IMEI for the SIM card in the specified slot. This API uses a promise to return the result. **System API**: This is a system API. @@ -1091,7 +1091,7 @@ promise.then(data => { getMEID\(callback: AsyncCallback\\): void -Obtains the MEID of the SIM card in a card slot. This API uses an asynchronous callback to return the result. +Obtains the MEID for the SIM card in a card slot. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -1132,7 +1132,7 @@ radio.getMEID((err, data) => { getMEID\(slotId: number, callback: AsyncCallback\\): void -Obtains the MEID of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. +Obtains the MEID for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -1175,7 +1175,7 @@ radio.getMEID(slotId, (err, data) => { getMEID\(slotId?: number\): Promise\ -Obtains the MEID of the SIM card in the specified slot. This API uses a promise to return the result. +Obtains the MEID for the SIM card in the specified slot. This API uses a promise to return the result. **System API**: This is a system API. @@ -1225,7 +1225,7 @@ promise.then(data => { getUniqueDeviceId\(callback: AsyncCallback\\): void -Obtains the unique device ID of the SIM card in a card slot. This API uses an asynchronous callback to return the result. +Obtains the unique device ID for the SIM card in a card slot. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -1266,7 +1266,7 @@ radio.getUniqueDeviceId((err, data) => { getUniqueDeviceId\(slotId: number, callback: AsyncCallback\\): void -Obtains the unique device ID of the SIM card in the specified slot. This API uses an asynchronous callback to return the result. +Obtains the unique device ID for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. **System API**: This is a system API. @@ -1309,7 +1309,7 @@ radio.getUniqueDeviceId(slotId, (err, data) => { getUniqueDeviceId\(slotId?: number\): Promise\ -Obtains the unique device ID of the SIM card in the specified slot. This API uses a promise to return the result. +Obtains the unique device ID for the SIM card in the specified slot. This API uses a promise to return the result. **System API**: This is a system API. @@ -2867,6 +2867,206 @@ promise.then(data => { ``` +## radio.getNetworkCapability10+ + +getNetworkCapability\(slotId: number, type: NetworkCapabilityType, callback: AsyncCallback\\): void + +Obtains the network capability for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. + +**System API**: This is a system API. + +**Required permission**: ohos.permission.GET_TELEPHONY_STATE + +**System capability**: SystemCapability.Telephony.CoreService + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | -----------------------------------------------------------------------| ---- | ----------------------------------- | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| +| type | [NetworkCapabilityType](#networkcapabilitytype10) | Yes | Network capability type. | +| callback | AsyncCallback\<[NetworkCapabilityState](#networkcapabilitystate10)\> | Yes | Callback used to return the result. | + +**Error codes** + +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + +| ID| Error Message | +| -------- | -------------------------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 8300001 | Invalid parameter value. | +| 8300002 | Operation failed. Cannot connect to service. | +| 8300003 | System internal error. | +| 8300999 | Unknown error code. | + +**Example** + +```js +let slotId = 0; +let type = radio.NetworkCapabilityType.SERVICE_TYPE_NR; +radio.getNetworkCapability(slotId, type, (err, data) => { + console.log(`callback: err->${JSON.stringify(err)}, data->${JSON.stringify(data)}`); +}); +``` + + +## radio.getNetworkCapability10+ + +getNetworkCapability\(slotId: number, type: NetworkCapabilityType\): Promise\ + +Obtains the network capability for the SIM card in the specified slot. This API uses a promise to return the result. + +**System API**: This is a system API. + +**Required permission**: ohos.permission.GET_TELEPHONY_STATE + +**System capability**: SystemCapability.Telephony.CoreService + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------------------- | ---- | -------------------------------------- | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| +| type | [NetworkCapabilityType](#networkcapabilitytype10) | Yes | Network capability type. | + +**Return value** + +| Type | Description | +| ------------------------------------------------------------- | ----------------------- | +| Promise\<[NetworkCapabilityState](#networkcapabilitystate10)\> | Promise used to return the result.| + +**Error codes** + +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + +| ID| Error Message | +| -------- | -------------------------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 8300001 | Invalid parameter value. | +| 8300002 | Operation failed. Cannot connect to service. | +| 8300003 | System internal error. | +| 8300999 | Unknown error code. | + +**Example** + +```js +let slotId = 0; +let type = radio.NetworkCapabilityType.SERVICE_TYPE_NR; +let promise = radio.getNetworkCapability(slotId, type); +promise.then(data => { + console.log(`getNetworkCapability success, promise: data->${JSON.stringify(data)}`); +}).catch(err => { + console.log(`getNetworkCapability failed, promise: err->${JSON.stringify(err)}`); +}); +``` + + +## radio.setNetworkCapability10+ + +setNetworkCapability\(slotId: number, type: NetworkCapabilityType, state: NetworkCapabilityState, + callback: AsyncCallback\\): void + +Sets the network capability for the SIM card in the specified slot. This API uses an asynchronous callback to return the result. + +**System API**: This is a system API. + +**Required permission**: ohos.permission.SET_TELEPHONY_STATE + +**System capability**: SystemCapability.Telephony.CoreService + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------------------- | ---- | -------------------------------------- | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| +| type | [NetworkCapabilityType](#networkcapabilitytype10) | Yes | Network capability type. | +| state | [NetworkCapabilityState](#networkcapabilitystate10) | Yes | Network capability status. | +| callback | AsyncCallback\ | Yes | Callback used to return the result. | + +**Error codes** + +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + +| ID| Error Message | +| -------- | -------------------------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 8300001 | Invalid parameter value. | +| 8300002 | Operation failed. Cannot connect to service. | +| 8300003 | System internal error. | +| 8300999 | Unknown error code. | + +**Example** + +```js +let slotId = 0; +let type = radio.NetworkCapabilityType.SERVICE_TYPE_NR; +let state = radio.NetworkCapabilityState.SERVICE_CAPABILITY_ON; +radio.setNetworkCapability(slotId, type, state, (err) => { + console.log(`callback: err->${JSON.stringify(err)}`); +}); +``` + +## radio.setNetworkCapability10+ + +setNetworkCapability\(slotId: number, type: NetworkCapabilityType, state: NetworkCapabilityState\): Promise\ + +Sets the network capability for the SIM card in the specified slot. This API uses a promise to return the result. + +**System API**: This is a system API. + +**Required permission**: ohos.permission.SET_TELEPHONY_STATE + +**System capability**: SystemCapability.Telephony.CoreService + +**Parameters** + +| Name | Type | Mandatory| Description | +| -------- | --------------------------------------------------------------- | ---- | -------------------------------------- | +| slotId | number | Yes | Card slot ID.
- **0**: card slot 1
- **1**: card slot 2| +| type | [NetworkCapabilityType](#networkcapabilitytype10) | Yes | Network capability type. | +| state | [NetworkCapabilityState](#networkcapabilitystate10) | Yes | Network capability status. | + +**Return value** + +| Type | Description | +| --------------- | ----------------------- | +| Promise\ | Promise used to return the result.| + +**Error codes** + +For details about the following error codes, see [Telephony Error Codes](../../reference/errorcodes/errorcode-telephony.md). + +| ID| Error Message | +| -------- | -------------------------------------------- | +| 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | +| 401 | Parameter error. | +| 8300001 | Invalid parameter value. | +| 8300002 | Operation failed. Cannot connect to service. | +| 8300003 | System internal error. | +| 8300999 | Unknown error code. | + +**Example** + +```js +let slotId = 0; +let type = radio.NetworkCapabilityType.SERVICE_TYPE_NR; +let state = radio.NetworkCapabilityState.SERVICE_CAPABILITY_ON; +let promise = radio.setNetworkCapability(slotId, type, state); +promise.then(data => { + console.log(`setNetworkCapability success, promise: data->${JSON.stringify(data)}`); +}).catch(err => { + console.log(`setNetworkCapability failed, promise: err->${JSON.stringify(err)}`); +}); +``` + + ## RadioTechnology Enumerates radio access technologies. @@ -3290,3 +3490,29 @@ Enumerates IMS service types. | TYPE_VIDEO | 1 | Video service.| | TYPE_UT | 2 | UT service. | | TYPE_SMS | 3 | SMS service.| + +## NetworkCapabilityType10+ + +Network capability type. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Telephony.CoreService + +| Name | Value | Description | +| -----------------| ---- | ---------- | +| SERVICE_TYPE_LTE | 0 | LTE service.| +| SERVICE_TYPE_NR | 1 | NR service.| + +## NetworkCapabilityState10+ + +Defines the network capability switch status. + +**System API**: This is a system API. + +**System capability**: SystemCapability.Telephony.CoreService + +| Name | Value | Description | +| -----------------------| ---- | ---------- | +| SERVICE_CAPABILITY_OFF | 0 | The network capability is disabled.| +| SERVICE_CAPABILITY_ON | 1 | The network capability is enabled.| diff --git a/en/application-dev/reference/apis/js-apis-resource-manager.md b/en/application-dev/reference/apis/js-apis-resource-manager.md index a1b98717279f99d9e15c5018fcf41bb28d30c6a5..0b991202add9b4a0480f3990ccc7f1775f95f3ba 100644 --- a/en/application-dev/reference/apis/js-apis-resource-manager.md +++ b/en/application-dev/reference/apis/js-apis-resource-manager.md @@ -151,6 +151,45 @@ Obtains the **ResourceManager** object of an application based on the specified ``` +## resourceManager.getSystemResourceManager10+ + +getSystemResourceManager(): ResourceManager + +Obtains a **ResourceManager** object. + +**System capability**: SystemCapability.Global.ResourceManager + +**Return value** + +| Type | Description | +| ---------------------------------------- | ------------------ | +| Resourcemanager | **ResourceManager** object.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001009 | If application can't access system resource. | + +**Example** + ```js +import resourceManager from '@ohos.resourceManager'; + +try { + let systemResourceManager = resourceManager.getSystemResourceManager(); + systemResourceManager.getStringValue($r('sys.string.ohos_lab_vibrate').id).then(value => { + let str = value; + }).catch(error => { + console.log("systemResourceManager getStringValue promise error is " + error); + }); +} catch (error) { + console.error(`systemResourceManager getStringValue failed, error code: ${error.code}, message: ${error.message}.`) +} + ``` + + ## Direction Enumerates the screen directions. @@ -3249,6 +3288,451 @@ For details about the error codes, see [Resource Manager Error Codes](../errorco } ``` +### getColor10+ + +getColor(resId: number, callback: AsyncCallback<number>): void; + +Obtains the color value corresponding to the specified resource ID. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------- | +| resId | number | Yes | Resource ID. | +| callback | AsyncCallback<number> | Yes | Asynchronous callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the module resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | + +**Example (stage)** + ```ts + try { + this.context.resourceManager.getColor($r('app.color.test').id, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } + }); + } catch (error) { + console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getColor10+ + +getColor(resId: number): Promise<number> + +Obtains the color value corresponding to the specified resource ID. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| + +**Return value** + +| Type | Description | +| --------------------- | ----------- | +| Promise<number> | Color value corresponding to the resource ID (decimal).| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + try { + this.context.resourceManager.getColor($r('app.color.test').id).then(value => { + let str = value; + }).catch(error => { + console.log("getColor promise error is " + error); + }); + } catch (error) { + console.error(`promise getColor failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getColor10+ + +getColor(resource: Resource, callback: AsyncCallback<number>): void; + +Obtains the color value corresponding to the specified resource object. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------- | +| resource | [Resource](#resource9) | Yes | Resource object. | +| callback | AsyncCallback<number> | Yes | Asynchronous callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.color.test').id + }; + try { + this.context.resourceManager.getColor(resource, (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let str = value; + } + }); + } catch (error) { + console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getColor10+ + +getColor(resource: Resource): Promise<number>; + +Obtains the color value corresponding to the specified resource object. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| + +**Return value** + +| Type | Description | +| --------------------- | ---------------- | +| Promise<number> | Color value corresponding to the resource object (decimal).| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.color.test').id + }; + try { + this.context.resourceManager.getColor(resource).then(value => { + let str = value; + }).catch(error => { + console.log("getColor promise error is " + error); + }); + } catch (error) { + console.error(`callback getColor failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getColorByName10+ + +getColorByName(resName: string, callback: AsyncCallback<number>): void + +Obtains the color value corresponding to the specified resource name. This API uses an asynchronous callback to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | --------------------------- | ---- | --------------- | +| resName | string | Yes | Resource name. | +| callback | AsyncCallback<number> | Yes | Asynchronous callback used to return the result.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + try { + this.context.resourceManager.getColorByName("test", (error, value) => { + if (error != null) { + console.log("error is " + error); + } else { + let string = value; + } + }); + } catch (error) { + console.error(`callback getColorByName failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getColorByName10+ + +getStringByName(resName: string): Promise<number> + +Obtains the color value corresponding to the specified resource name. This API uses a promise to return the result. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| + +**Return value** + +| Type | Description | +| --------------------- | ---------- | +| Promise<number> | Color value corresponding to the resource name (decimal).| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + try { + this.context.resourceManager.getColorByName("test").then(value => { + let string = value; + }).catch(error => { + console.log("getColorByName promise error is " + error); + }); + } catch (error) { + console.error(`promise getColorByName failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getColorSync10+ + +getColorSync(resId: number) : number; + +Obtains the color value corresponding to the specified resource ID. The API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ----- | ------ | ---- | ----- | +| resId | number | Yes | Resource ID.| + +**Return value** + +| Type | Description | +| ------ | ----------- | +| number | Color value corresponding to the resource ID (decimal).| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + try { + this.context.resourceManager.getColorSync($r('app.color.test').id); + } catch (error) { + console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getColorSync10+ + +getColorSync(resource: Resource): number + +Obtains the color value corresponding to the specified resource object. The API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| resource | [Resource](#resource9) | Yes | Resource object.| + +**Return value** + +| Type | Description | +| ------ | ---------------- | +| number | Color value corresponding to the resource object (decimal).| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001001 | If the resId invalid. | +| 9001002 | If the resource not found by resId. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + let resource = { + bundleName: "com.example.myapplication", + moduleName: "entry", + id: $r('app.color.test').id + }; + try { + this.context.resourceManager.getColorSync(resource); + } catch (error) { + console.error(`getColorSync failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### getColorByNameSync10+ + +getColorByNameSync(resName: string) : number; + +Obtains the color value corresponding to the specified resource name. The API returns the result synchronously. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ---- | +| resName | string | Yes | Resource name.| + +**Return value** + +| Type | Description | +| ------ | ---------- | +| number | Color value corresponding to the resource name (decimal).| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001003 | If the resName invalid. | +| 9001004 | If the resource not found by resName. | +| 9001006 | If the resource re-ref too much. | + +**Example** + ```ts + try { + this.context.resourceManager.getColorByNameSync("test"); + } catch (error) { + console.error(`getColorByNameSync failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### addResource10+ + +addResource(path: string) : void; + +Loads resources from the specified path. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| path | string | Yes | Resource path.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001010 | If the overlay path is invalid. | + +**Example** + ```ts + let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; + try { + this.context.resourceManager.addResource(path); + } catch (error) { + console.error(`addResource failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + +### removeResource10+ + +removeResource(path: string) : void; + +Removes the resources loaded from the specified path to restore the original resources. + +**System capability**: SystemCapability.Global.ResourceManager + +**Parameters** + +| Name | Type | Mandatory | Description | +| -------- | ---------------------- | ---- | ---- | +| path | string | Yes | Resource path.| + +**Error codes** + +For details about the error codes, see [Resource Manager Error Codes](../errorcodes/errorcode-resource-manager.md). + +| ID| Error Message| +| -------- | ---------------------------------------- | +| 9001010 | If the overlay path is invalid. | + +**Example** + ```ts + let path = getContext().bundleCodeDir + "/library1-default-signed.hsp"; + try { + this.resmgr.removeResource(path); + } catch (error) { + console.error(`removeResource failed, error code: ${error.code}, message: ${error.message}.`) + } + ``` + ### getString(deprecated) getString(resId: number, callback: AsyncCallback<string>): void diff --git a/en/application-dev/reference/apis/js-apis-usbManager.md b/en/application-dev/reference/apis/js-apis-usbManager.md index ac6de75dd00fc24d9503039fdae5bf6be0931ee7..204318356f38eca412eed855ddff9d0e324a8463 100644 --- a/en/application-dev/reference/apis/js-apis-usbManager.md +++ b/en/application-dev/reference/apis/js-apis-usbManager.md @@ -152,7 +152,7 @@ Checks whether the user, for example, the application or system, has the device **Example** ```js -let devicesName="1-1"; +let devicesName = "1-1"; let bool = usb.hasRight(devicesName); console.log(`${bool}`); ``` @@ -180,7 +180,7 @@ Requests the temporary permission for the application to access a USB device. Th **Example** ```js -let devicesName="1-1"; +let devicesName = "1-1"; usb.requestRight(devicesName).then((ret) => { console.log(`requestRight = ${ret}`); }); @@ -209,7 +209,7 @@ Removes the permission for the application to access a USB device. **Example** ```js -let devicesName= "1-1"; +let devicesName = "1-1"; if (usb.removeRight(devicesName)) { console.log(`Succeed in removing right`); } @@ -277,6 +277,15 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **Example** ```js +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +let device = devicesList[0]; +usb.requestRight(device.name); +let devicepipe = usb.connectDevice(device); +let interfaces = device.configs[0].interfaces[0]; let ret = usb.claimInterface(devicepipe, interfaces); console.log(`claimInterface = ${ret}`); ``` @@ -307,7 +316,17 @@ Before you do this, ensure that you have claimed the interface by calling [usb.c **Example** ```js -let ret = usb.releaseInterface(devicepipe, interfaces); +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +let device = devicesList[0]; +usb.requestRight(device.name); +let devicepipe = usb.connectDevice(device); +let interfaces = device.configs[0].interfaces[0]; +let ret = usb.claimInterface(devicepipe, interfaces); +ret = usb.releaseInterface(devicepipe, interfaces); console.log(`releaseInterface = ${ret}`); ``` @@ -337,6 +356,15 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **Example** ```js +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +let device = devicesList[0]; +usb.requestRight(device.name); +let devicepipe = usb.connectDevice(device); +let config = device.configs[0]; let ret = usb.setConfiguration(devicepipe, config); console.log(`setConfiguration = ${ret}`); ``` @@ -367,7 +395,17 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **Example** ```js -let ret = usb.setInterface(devicepipe, interfaces); +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +let device = devicesList[0]; +usb.requestRight(device.name); +let devicepipe = usb.connectDevice(device); +let interfaces = device.configs[0].interfaces[0]; +let ret = usb.claimInterface(devicepipe, interfaces); +ret = usb.setInterface(devicepipe, interfaces); console.log(`setInterface = ${ret}`); ``` @@ -396,6 +434,13 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **Example** ```js +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +usb.requestRight(devicesList[0].name); +let devicepipe = usb.connectDevice(devicesList[0]); let ret = usb.getRawDescriptor(devicepipe); ``` @@ -424,6 +469,13 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **Example** ```js +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +usb.requestRight(devicesList[0].name); +let devicepipe = usb.connectDevice(devicesList[0]); let ret = usb.getFileDescriptor(devicepipe); ``` @@ -462,6 +514,14 @@ let param = { index: 0, data: null }; + +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +usb.requestRight(devicesList[0].name); +let devicepipe = usb.connectDevice(devicesList[0]); usb.controlTransfer(devicepipe, param).then((ret) => { console.log(`controlTransfer = ${ret}`); }) @@ -498,8 +558,21 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi // Call usb.getDevices to obtain a data set. Then, obtain a USB device and its access permission. // Pass the obtained USB device as a parameter to usb.connectDevice. Then, call usb.connectDevice to connect the USB device. // Call usb.claimInterface to claim the USB interface. After that, call usb.bulkTransfer to start bulk transfer. +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +let device = devicesList[0]; +usb.requestRight(device.name); + +let devicepipe = usb.connectDevice(device); +let interfaces = device.configs[0].interfaces[0]; +let endpoint = device.configs[0].interfaces[0].endpoints[0]; +let ret = usb.claimInterface(devicepipe, interfaces); +let buffer = new Uint8Array(128); usb.bulkTransfer(devicepipe, endpoint, buffer).then((ret) => { - console.log(`bulkTransfer = ${ret}`); + console.log(`bulkTransfer = ${ret}`); }); ``` @@ -528,6 +601,13 @@ Before you do this, call [usb.getDevices](#usbgetdevices) to obtain the USB devi **Example** ```js +let devicesList = usb.getDevices(); +if (devicesList.length == 0) { + console.log(`device list is empty`); +} + +usb.requestRight(devicesList[0].name); +let devicepipe = usb.connectDevice(devicesList[0]); let ret = usb.closePipe(devicepipe); console.log(`closePipe = ${ret}`); ``` @@ -606,6 +686,14 @@ Sets the current USB function list in Device mode. | ------ | ------------------------------ | ---- | ----------------- | | funcs | [FunctionType](#functiontype) | Yes | USB function list in numeric mask format.| +**Error codes** + +For details about the error codes, see [USB Error Codes](../errorcodes/errorcode-usb.md). + +| ID| Error Message | +| -------- | ---------------------------------------------------- | +| 14400002 | Permission denied.The HDC is disabled by the system. | + **Return value** | Type | Description | diff --git a/en/application-dev/reference/errorcodes/errorcode-resource-manager.md b/en/application-dev/reference/errorcodes/errorcode-resource-manager.md index d22ffb059b5459811ba5f332be94155c50022886..0087cce7e7069ed7efcab185e3c51be883dee13e 100644 --- a/en/application-dev/reference/errorcodes/errorcode-resource-manager.md +++ b/en/application-dev/reference/errorcodes/errorcode-resource-manager.md @@ -12,15 +12,15 @@ The resId invalid. **Description** -This error code is reported if the specified resource ID meets the type requirement but the resource ID does not exist. +This error code is reported if the specified resId meets the type requirement but the **resId** does not exist. **Possible Causes** -The specified resource ID does not exist. +The specified **resId** does not exist. **Solution** -Check whether the specified resource ID exists. +Check whether the specified **resId** exists. ## 9001002 Matching Resource Not Found Based on the Specified Resource ID @@ -30,17 +30,17 @@ The resource not found by resId. **Description** -This error code is reported if the specified resource ID meets the type requirement but no resource is found based on the resource ID. +This error code is reported if the specified **resId** meets the type requirement but no resource is found based on the **resId**. **Possible Causes** -1. The specified resource ID is incorrect. +1. The specified **resId** is incorrect. 2. Resource parsing is incorrect. **Solution** -Check whether the specified resource ID is correct. +Check whether the specified **resId** is correct. ## 9001003 Invalid Resource Name @@ -50,15 +50,15 @@ The resName invalid. **Description** -This error code is reported if the specified resource name meets the type requirement but the resource name does not exist. +This error code is reported if the specified **resName** meets the type requirement but the **resName** does not exist. **Possible Causes** -The specified resource name does not exist. +The specified **resName** does not exist. **Solution** -Check whether the specified resource name is correct. +Check whether the specified **resName** is correct. ## 9001004 Matching Resource Not Found Based on the Specified Resource Name @@ -68,17 +68,17 @@ The resource not found by resName. **Description** -This error code is reported if the specified resource ID meets the type requirement but no resource is found based on the resource ID. +This error code is reported if the specified resId meets the type requirement but no resource is found based on the **resId**. **Possible Causes** -1. The specified resource name is incorrect. +1. The specified **resName** is incorrect. 2. Resource parsing is incorrect. **Solution** -Check whether the specified resource name is correct. +Check whether the specified **resName** is correct. ## 9001005 Invalid Relative Path @@ -115,3 +115,65 @@ Resources are referenced cyclically. **Solution** Check the reference of resource $, and remove the cyclic reference, if any. + +## 9001007 Failed to Format the Resource Obtained Based on resId + +**Error Message** + +The resource obtained by resId formatting error. + +**Description** + +This error code is reported in the case of a failure to format the string resource obtained based on **resId**. + +**Possible Causes** + +1. The parameter type is not supported. + +2. The numbers of parameters and placeholders are inconsistent. + +3. The parameter does not match the placeholder type. + +**Solution** + +Check whether the number and type of **args** parameters are the same as those of placeholders. + +## 9001008 Failed to Format the Resource Obtained Based on resName + +**Error Message** + +The resource obtained by resName formatting error. + +**Description** + +This error code is reported in the case of a failure to format the string resource obtained based on **resName**. + +**Possible Causes** + +1. The parameter type is not supported. + +2. The numbers of parameters and placeholders are inconsistent. + +3. The parameter does not match the placeholder type. + +**Solution** + +Check whether the number and type of **args** parameters are the same as those of placeholders. + +## 9001009 Failed to Obtain a ResourceManager Object + +**Error Message** + +Get system resource manager failed. + +**Description** + +This error code is reported in the case of a failure to obtain a ResourceManager object. + +**Possible Causes** + +System resources are not loaded to the sandbox path of the application process. + +**Solution** + +Check whether the application process contains the sandbox path of system resources. diff --git a/en/application-dev/reference/errorcodes/errorcode-usb.md b/en/application-dev/reference/errorcodes/errorcode-usb.md index a29c15a13d740a4f8cdf6a9e62fea6dc9131ff77..f60d87274b9990a8c53cb6d8872a4cf852d535d2 100644 --- a/en/application-dev/reference/errorcodes/errorcode-usb.md +++ b/en/application-dev/reference/errorcodes/errorcode-usb.md @@ -21,3 +21,21 @@ The permission to access the USB device is not granted. **Solution** Call **requestRight** to request for the permission to access the USB device. + +## 14400002 HDC Disabled + +**Error Message** + +Permission denied.The HDC is disabled by the system. + +**Description** + +This error code is reported if HDC is disabled by the system. + +**Possible Causes** + +The USB debugging permission is not available. + +**Solution** + +Apply for the USB debugging permission. diff --git a/en/application-dev/reference/native-apis/_hitrace.md b/en/application-dev/reference/native-apis/_hitrace.md new file mode 100644 index 0000000000000000000000000000000000000000..995308c7599bda3f33b27224a038ce64377fdeb7 --- /dev/null +++ b/en/application-dev/reference/native-apis/_hitrace.md @@ -0,0 +1,154 @@ +# Hitrace + + +## Overview + +hiTraceMeter provides APIs for system performance tracing. + +You can call the APIs provided by hiTraceMeter in your own service logic to effectively track service processes and check the system performance. + +\@syscap SystemCapability.HiviewDFX.HiTrace + +**Since** + +10 + + +## Summary + + +### File + +| Name| Description| +| -------- | -------- | +| [trace.h](trace_8h.md) | Defines APIs of the HiTraceMeter module for performance trace.
**File to include**:
**Library**: libhitrace_ndk.z.so| + +### Functions + +| Name| Description| +| -------- | -------- | +| [OH_HiTrace_StartTrace](#oh_hitrace_starttrace) (const char \*name) | Marks the start of a synchronous trace.| +| [OH_HiTrace_FinishTrace](#oh_hitrace_finishtrace) (void) | Marks the end of a synchronous trace.| +| [OH_HiTrace_StartAsyncTrace](#oh_hitrace_startasynctrace) (const char \*name, int32_t taskId) | Marks the start of an asynchronous trace.| +| [OH_HiTrace_FinishAsyncTrace](#oh_hitrace_finishasynctrace) (const char \*name, int32_t taskId) | Marks the end of an asynchronous trace.| +| [OH_HiTrace_CountTrace](#oh_hitrace_counttrace) (const char \*name, int64_t count) | Traces the value change of an integer variable based on its name.| + + +## Function Description + + +### OH_HiTrace_CountTrace() + + +``` +void OH_HiTrace_CountTrace (const char * name, int64_t count ) +``` + +**Description** + +Traces the value change of an integer variable based on its name. + +This API can be executed for multiple times to trace the value change of a given integer variable at different time points. + +**Parameters** + +| Name| Description| +| -------- | -------- | +| name | Name of the integer variable. It does not need to be the same as the real variable name.| +| count | Integer value. Generally, an integer variable can be specified.| + +**Since** + +10 + + +### OH_HiTrace_FinishAsyncTrace() + + +``` +void OH_HiTrace_FinishAsyncTrace (const char * name, int32_t taskId ) +``` + +**Description** + +Marks the end of an asynchronous trace. + +This API is called in the callback function after an asynchronous trace is complete. It is used with **OH_HiTrace_StartAsyncTrace** in pairs. Its name and task ID must be the same as those of **OH_HiTrace_StartAsyncTrace**. + +**Parameters** + +| Name| Description| +| -------- | -------- | +| name | Name of the asynchronous trace.| +| taskId | ID of the asynchronous trace. The start and end of an asynchronous trace task do not occur in sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the unique task ID together.| + +**Since** + +10 + + +### OH_HiTrace_FinishTrace() + + +``` +void OH_HiTrace_FinishTrace (void ) +``` + +**Description** + +Marks the end of a synchronous trace. + +This API must be used with **OH_HiTrace_StartTrace** in pairs. During trace data parsing, the system matches it with the **OH_HiTrace_StartTrace** API recently invoked in the service process. + +**Since** + +10 + + +### OH_HiTrace_StartAsyncTrace() + + +``` +void OH_HiTrace_StartAsyncTrace (const char * name, int32_t taskId ) +``` + +**Description** + +Marks the start of an asynchronous trace. + +This API is called to implement performance trace in asynchronous manner. The start and end of an asynchronous trace task do not occur in sequence. Therefore, a unique **taskId** is required to ensure proper data parsing. It is passed as an input parameter for the asynchronous API. This API is used with **OH_HiTrace_FinishAsyncTrace** in pairs. The two APIs that have the same name and task ID together form an asynchronous trace. If multiple trace tasks with the same name need to be performed at the same time or a trace task needs to be performed multiple times concurrently, different task IDs must be specified in **OH_HiTrace_StartTrace**. If the trace tasks with the same name are not performed at the same time, the same taskId can be used. + +**Parameters** + +| Name| Description| +| -------- | -------- | +| name | Name of an asynchronous trace.| +| taskId | ID of the asynchronous trace. The start and end of an asynchronous trace task do not occur in sequence. Therefore, the start and end of an asynchronous trace need to be matched based on the task name and the unique task ID together.| + +**Since** + +10 + + +### OH_HiTrace_StartTrace() + + +``` +void OH_HiTrace_StartTrace (const char * name) +``` + +**Description** + +Marks the start of a synchronous trace. + +This API is used with **OH_HiTrace_FinishTrace** in pairs. The two APIs can be used in nested mode. The stack data structure is used for matching during trace data parsing. + +**Parameters** + +| Name| Description| +| -------- | -------- | +| name | Name of the synchronous trace.| + +**Since** + +10 diff --git a/en/application-dev/reference/native-apis/trace_8h.md b/en/application-dev/reference/native-apis/trace_8h.md new file mode 100644 index 0000000000000000000000000000000000000000..56f88fea16ea387e36b917a89e63fe7034809812 --- /dev/null +++ b/en/application-dev/reference/native-apis/trace_8h.md @@ -0,0 +1,76 @@ +# trace.h + + +## Overview + +Defines APIs of the HiTraceMeter module for performance trace. + +Example + +Synchronous time slice trace event: + + +``` +OH_HiTrace_StartTrace("hitraceTest"); +OH_HiTrace_FinishTrace(); +``` + +Output: + + +``` +<...>-1668 (----—) [003] .... 135.059377: tracing_mark_write: B|1668|H:hitraceTest +<...>-1668 (----—) [003] .... 135.059415: tracing_mark_write: E|1668| +``` + +Asynchronous time slice trace event: + + +``` +OH_HiTrace_StartAsyncTrace("hitraceTest", 123); +OH_HiTrace_FinishAsyncTrace("hitraceTest", 123); +``` + +Output: + + +``` +<...>-2477 (----—) [001] .... 396.427165: tracing_mark_write: S|2477|H:hitraceTest 123 +<...>-2477 (----—) [001] .... 396.427196: tracing_mark_write: F|2477|H:hitraceTest 123 +``` + +Integer value trace event: + + +``` +OH_HiTrace_CountTrace("hitraceTest", 500); +``` + +Output: + + +``` +<...>-2638 (----—) [002] .... 458.904382: tracing_mark_write: C|2638|H:hitraceTest 500 +``` + +**Since** + +10 + +**Related Modules** + +[Hitrace](_hitrace.md) + + +## Summary + + +### Functions + +| Name| Description| +| -------- | -------- | +| [OH_HiTrace_StartTrace](_hitrace.md#oh_hitrace_starttrace) (const char \*name) | Marks the start of a synchronous trace.| +| [OH_HiTrace_FinishTrace](_hitrace.md#oh_hitrace_finishtrace) (void) | Marks the end of a synchronous trace.| +| [OH_HiTrace_StartAsyncTrace](_hitrace.md#oh_hitrace_startasynctrace) (const char \*name, int32_t taskId) | Marks the start of an asynchronous trace.| +| [OH_HiTrace_FinishAsyncTrace](_hitrace.md#oh_hitrace_finishasynctrace) (const char \*name, int32_t taskId) | Marks the end of an asynchronous trace.| +| [OH_HiTrace_CountTrace](_hitrace.md#oh_hitrace_counttrace) (const char \*name, int64_t count) | Traces the value change of an integer variable based on its name.| diff --git a/en/device-dev/subsystems/subsys-thermal_log.md b/en/device-dev/subsystems/subsys-thermal_log.md index 2e889e833a99a13a492ce58c2c2cc04ab0643423..a9b9b5f7ae4dbc0796c4064fe2102c060e41b9cc 100644 --- a/en/device-dev/subsystems/subsys-thermal_log.md +++ b/en/device-dev/subsystems/subsys-thermal_log.md @@ -26,7 +26,7 @@ For details about the requirements on the Linux environment, see [Quick Start](. The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate thermal log customization. -1. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568). +1. Create the thermal folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568). 2. Create a target folder by referring to the [default thermal log configuration folder](https://gitee.com/openharmony/drivers_peripheral/tree/master/thermal/interfaces/hdi_service/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows: @@ -50,8 +50,6 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma | Configuration Item| Description| Data Type| Value Range| | -------- | -------- | -------- | -------- | - | interval | Interval for recording temperature tracing logs, in ms.| int | >0 | - | width | Width of the temperature tracing log, in characters.| int | >0 | | outpath | Path for storing temperature tracing logs.| string | N/A| **Table 2** Description of the node configuration @@ -63,7 +61,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma | value | path | Path for obtaining the thermal zone temperature.| ```shell - + <value path="sys/class/thermal/thermal_zone0/temp"/> @@ -86,10 +84,10 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma thermal.para.dac: ```text - persist.thermal.log.="power_host:power_host:600" # Configure access permissions. + persist.thermal.log.="power_host:power_host:500" # Configure access permissions. ``` -6. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn) file in the default thermal log configuration folder to pack the `thermal_hdi_config.xml` file to the `//vendor/etc/thermal_config/hdf` directory. The configuration is as follows: +6. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/drivers_peripheral/blob/master/thermal/interfaces/hdi_service/profile/BUILD.gn) file in the default thermal log configuration folder to pack the thermal_hdi_config.xml file to the `//vendor/etc/thermal_config/hdf` directory. The configuration is as follows: ```shell import("//build/ohos.gni") @@ -97,7 +95,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma ohos_prebuilt_etc("thermal_hdf_config") { source = "thermal_hdi_config.xml" relative_install_dir = "thermal_config/hdf" - install_images = [ chipset_base_dir ] # Required configuration for installing the thermal_hdi_config.xml file in the vendor directory. + install_images = [ chipset_base_dir ] # Required configuration for installing the thermal_service_config.xml file in the vendor directory. part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. You can change it as required. } ``` @@ -151,7 +149,7 @@ The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/ma "subsystem": "product_hihope" } ``` - In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` and `etc` are folder names, and `thermal_hdf_config` and `param_files` are the build targets. + In the preceding code, //vendor/hihope/rk3568/thermal/ is the folder path, profile and etc are folder names, and thermal_hdf_config and param_files are the build targets. 9. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). diff --git a/en/release-notes/changelogs/v4.0-beta1/Readme-EN.md b/en/release-notes/changelogs/v4.0-beta1/Readme-EN.md index eba424652412699f84cddb477631fe4ec156b80c..10cca9e6fee269b59608b52d12cf7940faaf6fce 100644 --- a/en/release-notes/changelogs/v4.0-beta1/Readme-EN.md +++ b/en/release-notes/changelogs/v4.0-beta1/Readme-EN.md @@ -13,6 +13,8 @@ | ArkUI | UX changed | [The hover effect of the \<Button> component is changed from scale-up by 100% to 105% to overlay of 0% to 5% opacity.](changelogs-arkui.md)| | ArkUI | UX changed | [The alignment mode of multi-line text in toasts is changed from center-aligned to left-aligned.](changelogs-arkui.md)| | Bundle management subsystem | Mechanism changed | [The HAP is no longer decompressed during HAP installation.](changelogs-bundlemanager.md)| +| Globalization | API added | [The getStringSync and getStringByNameSync APIs are added.](changelogs-global.md)| +| Globalization | Behavior changed | [The meaning of the return value for the API used to obtain the rawfile descriptor is changed.](changelogs-global.md)| | Security-HUKS | Behavior changed | [HuksKeyStorageType must be passed in for key derivation or key agreement.](changelogs-huks.md) | | Security-HUKS | Behavior changed | [Permission is required for Using attestKeyItem.](changelogs-huks.md) | | Web | Input parameter added | [The input parameter type Resource is added for the setResponseData API.](changelogs-web.md) |