提交 f1fedc7a 编写于 作者: F fangyun

merge

Signed-off-by: Nfangyun <fangyun2@huawei.com>
...@@ -48,7 +48,7 @@ arkXtest is divided into two parts: unit test framework and UI test framework. ...@@ -48,7 +48,7 @@ arkXtest is divided into two parts: unit test framework and UI test framework.
Software for writing test scripts: DevEco Studio 3.0 or later Software for writing test scripts: DevEco Studio 3.0 or later
Hardware for running test scripts: PC connected to a OpenHarmony device, such as the RK3568 development board Hardware for running test scripts: PC connected to an OpenHarmony device, such as the RK3568 development board
### Setting Up the Environment ### Setting Up the Environment
...@@ -63,8 +63,8 @@ Hardware for running test scripts: PC connected to a OpenHarmony device, such as ...@@ -63,8 +63,8 @@ Hardware for running test scripts: PC connected to a OpenHarmony device, such as
## Writing a Unit Test Script ## Writing a Unit Test Script
```TS ```TS
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
import abilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' import abilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
const delegator = abilityDelegatorRegistry.getAbilityDelegator() const delegator = abilityDelegatorRegistry.getAbilityDelegator()
export default function abilityTest() { export default function abilityTest() {
...@@ -198,10 +198,11 @@ The framework supports multiple test case execution modes, which are triggered b ...@@ -198,10 +198,11 @@ The framework supports multiple test case execution modes, which are triggered b
| testType | Type of the test case to be executed. | function, performance, power, reliability, security, global, compatibility, user, standard, safety, resilience| -s testType function | | testType | Type of the test case to be executed. | function, performance, power, reliability, security, global, compatibility, user, standard, safety, resilience| -s testType function |
| level | Level of the test case to be executed. | 0, 1, 2, 3, 4 | -s level 0 | | level | Level of the test case to be executed. | 0, 1, 2, 3, 4 | -s level 0 |
| size | Size of the test case to be executed. | small, medium, large | -s size small | | size | Size of the test case to be executed. | small, medium, large | -s size small |
| stress | Number of times that the test case is executed. | Positive integer | -s stress 1000 |
**Running Commands** **Running Commands**
Configure hdc-related environment variables, and then perform the following: > Configure hdc-related environment variables, and then perform the following:
- Open the CLI. - Open the CLI.
- Run the **aa test** commands. - Run the **aa test** commands.
...@@ -260,12 +261,18 @@ Example 9: Execute test cases at the specified level. ...@@ -260,12 +261,18 @@ Example 9: Execute test cases at the specified level.
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s level 0 hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s level 0
``` ```
Example 10: Execute test cases with the specified level. Example 10: Execute test cases with the specified size.
```shell ```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s size small hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s size small
``` ```
Example 11: Execute test cases for a specified number of times.
```shell
hdc shell aa test -b xxx -p xxx -s unittest OpenHarmonyTestRunner -s stress 1000
```
**Viewing the Test Result** **Viewing the Test Result**
- During test execution in the CLI, the log information similar to the following is displayed: - During test execution in the CLI, the log information similar to the following is displayed:
...@@ -394,11 +401,11 @@ Run the following command, restart the device, and execute the test case again: ...@@ -394,11 +401,11 @@ Run the following command, restart the device, and execute the test case again:
hdc shell param set persist.ace.testmode.enabled 1 hdc shell param set persist.ace.testmode.enabled 1
``` ```
#### The failure log contains "uitest-api dose not allow calling concurrently" #### The failure log contains "uitest-api does not allow calling concurrently"
**Problem** **Problem**
The UI test case fails to be executed. The HiLog file contains the error message "uitest-api dose not allow calling concurrently". The UI test case fails to be executed. The HiLog file contains the error message "uitest-api does not allow calling concurrently".
**Possible Causes** **Possible Causes**
...@@ -412,11 +419,11 @@ The UI test case fails to be executed. The HiLog file contains the error message ...@@ -412,11 +419,11 @@ The UI test case fails to be executed. The HiLog file contains the error message
2. Do not execute UI test cases in multiple processes. 2. Do not execute UI test cases in multiple processes.
#### The failure log contains "dose not exist on current UI! Check if the UI has changed after you got the widget object" #### The failure log contains "does not exist on current UI! Check if the UI has changed after you got the widget object"
**Problem** **Problem**
The UI test case fails to be executed. The HiLog file contains the error message "dose not exist on current UI! Check if the UI has changed after you got the widget object". The UI test case fails to be executed. The HiLog file contains the error message "does not exist on current UI! Check if the UI has changed after you got the widget object".
**Possible Causes** **Possible Causes**
......
...@@ -15,9 +15,9 @@ import pointer from '@ohos.multimodalInput.pointer'; ...@@ -15,9 +15,9 @@ import pointer from '@ohos.multimodalInput.pointer';
The following table lists the common APIs for mouse pointer management. For details about the APIs, see [ohos.multimodalInput.pointer](../reference/apis/js-apis-pointer.md). The following table lists the common APIs for mouse pointer management. For details about the APIs, see [ohos.multimodalInput.pointer](../reference/apis/js-apis-pointer.md).
| Instance | API | Description | | Instance | API | Description |
| ------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | ------- | ------------------------------------------------------------ | --------------------------------------------------------------- |
| pointer | function isPointerVisible(callback: AsyncCallback\<boolean>): void; | Checks the visible status of the mouse pointer. | | pointer | function isPointerVisible(callback: AsyncCallback\<boolean>): void; | Checks the visible status of the mouse pointer. |
| pointer | function setPointerVisible(visible: boolean, callback: AsyncCallback\<void>): void; | Sets the visible status of the mouse pointer. This setting takes effect for the mouse pointer globally.| | pointer | function setPointerVisible(visible: boolean, callback: AsyncCallback\<void>): void; | Sets the visible status of the mouse pointer. This setting takes effect for the mouse pointer globally. |
| pointer | function setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback\<void>): void; | Sets the mouse pointer style. This setting takes effect for the mouse pointer style of a specified window. | | pointer | function setPointerStyle(windowId: number, pointerStyle: PointerStyle, callback: AsyncCallback\<void>): void; | Sets the mouse pointer style. This setting takes effect for the mouse pointer style of a specified window. |
| pointer | function getPointerStyle(windowId: number, callback: AsyncCallback\<PointerStyle>): void; | Obtains the mouse pointer style. | | pointer | function getPointerStyle(windowId: number, callback: AsyncCallback\<PointerStyle>): void; | Obtains the mouse pointer style. |
......
...@@ -8,7 +8,7 @@ In Host mode, you can obtain the list of connected USB devices, enable or disabl ...@@ -8,7 +8,7 @@ In Host mode, you can obtain the list of connected USB devices, enable or disabl
The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management. The USB service provides the following functions: query of USB device list, bulk data transfer, control transfer, and access permission management.
The following table lists the USB APIs currently available. For details, see the [API Reference](../reference/apis/js-apis-usb.md). The following table lists the USB APIs currently available. For details, see the [API Reference](../reference/apis/js-apis-usbManager.md).
**Table 1** Open USB APIs **Table 1** Open USB APIs
...@@ -18,7 +18,7 @@ The following table lists the USB APIs currently available. For details, see the ...@@ -18,7 +18,7 @@ The following table lists the USB APIs currently available. For details, see the
| requestRight(deviceName: string): Promise\<boolean> | Requests the temporary permission for a given application to access the USB device. This API uses a promise to return the result. | | requestRight(deviceName: string): Promise\<boolean> | Requests the temporary permission for a given application to access the USB device. This API uses a promise to return the result. |
| connectDevice(device: USBDevice): Readonly\<USBDevicePipe> | Connects to the USB device based on the device list returned by `getDevices()`. | | connectDevice(device: USBDevice): Readonly\<USBDevicePipe> | Connects to the USB device based on the device list returned by `getDevices()`. |
| getDevices(): Array<Readonly\<USBDevice>> | Obtains the list of USB devices connected to the USB host. If no USB device is connected, an empty list is returned. | | getDevices(): Array<Readonly\<USBDevice>> | Obtains the list of USB devices connected to the USB host. If no USB device is connected, an empty list is returned. |
| setConfiguration(pipe: USBDevicePipe, config: USBConfig): number | Sets the USB device configuration. | | setConfiguration(pipe: USBDevicePipe, config: USBConfiguration): number | Sets the USB device configuration. |
| setInterface(pipe: USBDevicePipe, iface: USBInterface): number | Sets a USB interface. | | setInterface(pipe: USBDevicePipe, iface: USBInterface): number | Sets a USB interface. |
| claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): number | Claims a USB interface. | | claimInterface(pipe: USBDevicePipe, iface: USBInterface, force ?: boolean): number | Claims a USB interface. |
| bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise\<number> | Performs bulk transfer. | | bulkTransfer(pipe: USBDevicePipe, endpoint: USBEndpoint, buffer: Uint8Array, timeout ?: number): Promise\<number> | Performs bulk transfer. |
...@@ -36,7 +36,7 @@ You can set a USB device as the USB host to connect to other USB devices for dat ...@@ -36,7 +36,7 @@ You can set a USB device as the USB host to connect to other USB devices for dat
```js ```js
// Import the USB API package. // Import the USB API package.
import usb from '@ohos.usbV9'; import usb from '@ohos.usbManager';
// Obtain the USB device list. // Obtain the USB device list.
let deviceList = usb.getDevices(); let deviceList = usb.getDevices();
/* /*
......
...@@ -39,7 +39,7 @@ Fault management is an important way for applications to deliver a better user e ...@@ -39,7 +39,7 @@ Fault management is an important way for applications to deliver a better user e
- Fault query indicates that [faultLogger](../reference/apis/js-apis-faultLogger.md) obtains the fault information using its query API. - Fault query indicates that [faultLogger](../reference/apis/js-apis-faultLogger.md) obtains the fault information using its query API.
The figure below does not illustrate the time when [faultLogger](../reference/apis/js-apis-faultLogger.md) is called. You can refer to [LastExitReason](../reference/apis/js-apis-application-abilityConstant.md#abilityconstantlastexitreason) passed during application initialization to determine whether to call [faultLogger](../reference/apis/js-apis-faultLogger.md) to query the information about the last fault. The figure below does not illustrate the time when [faultLogger](../reference/apis/js-apis-faultLogger.md) is called. You can refer to [LastExitReason](../reference/apis/js-apis-app-ability-abilityConstant.md#abilityconstantlastexitreason) passed during application initialization to determine whether to call [faultLogger](../reference/apis/js-apis-faultLogger.md) to query the information about the last fault.
![Fault rectification process](./figures/fault_rectification.png) ![Fault rectification process](./figures/fault_rectification.png)
It is recommended that you call [errorManager](../reference/apis/js-apis-application-errorManager.md) to process the exception. After the processing is complete, you can call the status saving API and restart the application. It is recommended that you call [errorManager](../reference/apis/js-apis-application-errorManager.md) to process the exception. After the processing is complete, you can call the status saving API and restart the application.
...@@ -134,7 +134,7 @@ After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state, ...@@ -134,7 +134,7 @@ After the callback triggers **appRecovery.saveAppState()**, **onSaveState(state,
- Restore data. - Restore data.
After the callback triggers **appRecovery.restartApp()**, the application is restarted. After the restart, **onSaveState(state, wantParams)** of **EntryAbility** is called, and the saved data is in **parameters** of **want**. After the callback triggers **appRecovery.restartApp()**, the application is restarted. After the restart, **onCreate(want, launchParam)** of **EntryAbility** is called, and the saved data is in **parameters** of **want**.
```ts ```ts
storage: LocalStorage storage: LocalStorage
......
# HiLog Development # HiLog Development
## Introduction
## Overview
HiLog is the log system of OpenHarmony that provides logging for the system framework, services, and applications to record information on user operations and system running status. HiLog is the log system of OpenHarmony that provides logging for the system framework, services, and applications to record information on user operations and system running status.
> **NOTE** > **NOTE**
>
> This development guide is applicable only when you use Native APIs for application development. For details about the APIs, see [HiLog Native API Reference](https://gitee.com/openharmony-sig/interface_native_header/blob/master/en/native_sdk/dfx/log.h). > This development guide is applicable only when you use Native APIs for application development. For details about the APIs, see [HiLog Native API Reference](https://gitee.com/openharmony-sig/interface_native_header/blob/master/en/native_sdk/dfx/log.h).
## Available APIs ## Available APIs
| API/Macro| Description| | API/Macro| Description|
| -------- | -------- | | -------- | -------- |
| int OH_LOG_Print(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) | Outputs logs based on the specified log type, log level, service domain, log tag, and variable parameters determined by the format specifier and privacy identifier in the printf format.| | int OH_LOG_Print(LogType type, LogLevel level, unsigned int domain, const char *tag, const char *fmt, ...) | Outputs logs based on the specified log type, log level, service domain, log tag, and variable parameters determined by the format specifier and privacy identifier in the printf format.<br>Input parameters: See [Parameter Description](#parameter-description).<br>Output parameters: None<br>Return value: total number of bytes if log printing is successful; **-1** otherwise.|
| #define OH_LOG_DEBUG(type, ...) ((void)OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__))| Outputs DEBUG logs. This is a function-like macro.| | #define OH_LOG_DEBUG(type, ...) ((void)OH_LOG_Print((type), LOG_DEBUG, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__))| Outputs DEBUG logs. This is a function-like macro.|
| #define OH_LOG_INFO(type, ...) ((void)OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__)) | Outputs INFO logs. This is a function-like macro.| | #define OH_LOG_INFO(type, ...) ((void)OH_LOG_Print((type), LOG_INFO, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__)) | Outputs INFO logs. This is a function-like macro.|
| #define OH_LOG_WARN(type, ...) ((void)OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__)) | Outputs WARN logs. This is a function-like macro.| | #define OH_LOG_WARN(type, ...) ((void)OH_LOG_Print((type), LOG_WARN, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__)) | Outputs WARN logs. This is a function-like macro.|
| #define OH_LOG_ERROR(type, ...) ((void)OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__)) | Outputs ERROR logs. This is a function-like macro.| | #define OH_LOG_ERROR(type, ...) ((void)OH_LOG_Print((type), LOG_ERROR, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__)) | Outputs ERROR logs. This is a function-like macro.|
| #define OH_LOG_FATAL(type, ...) ((void)OH_LOG_Print((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__)) | Outputs FATAL logs. This is a function-like macro.| | #define OH_LOG_FATAL(type, ...) ((void)OH_LOG_Print((type), LOG_FATAL, LOG_DOMAIN, LOG_TAG, \_*VA*ARGS__)) | Outputs FATAL logs. This is a function-like macro.|
| bool OH_LOG_IsLoggable(unsigned int domain, const char *tag, LogLevel level) | Checks whether logs of the specified service domain, tag, and level can be printed.<br>Input arguments:<br>- **domain**: service domain.<br>- **tag**: log tag.<br>- **level**: log level.<br>Output arguments: none<br>Return value: Returns **true** if the specified logs can be printed; returns **false** otherwise.| | bool OH_LOG_IsLoggable(unsigned int domain, const char *tag, LogLevel level) | Checks whether logs of the specified service domain, tag, and level can be printed.<br>Input parameters: See [Parameter Description](#parameter-description).<br>Output arguments: none<br>Return value: **true** if the specified logs can be printed; **false** otherwise.|
## Parameter Description
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| type | enum | Yes | Enum of log printing types. The default value is **LOG_APP** for application logs.|
| level | enum | Yes | Log printing level. For details, see [Log Level](#loglevel).|
| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**.<br>You can define the value as required. |
| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.|
| fmt | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **\<private>**.|
| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.|
## LogLevel
Log level.
| Name | Value | Description |
| ----- | ------ | ------------------------------------------------------------ |
| DEBUG | 3 | Log level used to record more detailed process information than INFO logs to help developers analyze service processes and locate faults.|
| INFO | 4 | Log level used to record key service process nodes and exceptions that occur during service running,<br>Log level used to record information about unexpected exceptions, such as network signal loss and login failure.<br>These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions.|
| WARN | 5 | Log level used to record severe, unexpected faults that have little impact on users and can be rectified by the programs themselves or through simple operations.|
| ERROR | 6 | Log level used to record program or functional errors that affect the normal running or use of the functionality and can be fixed at a high cost, for example, by resetting data.|
| FATAL | 7 | Log level used to record program or functionality crashes that cannot be rectified.
## Development Examples ## Development Examples
1. Include the **hilog** header file in the source file.
1. Add the link of **libhilog_ndk.z.so** to **CMakeLists.txt**:
```
target_link_libraries(entry PUBLIC libhilog_ndk.z.so)
```
2. Include the **hilog** header file in the source file, and define the **domain** and **tag** macros.
```c++ ```c++
#include "hilog/log.h" #include "hilog/log.h"
``` ```
2. Define the **domain** and **tag** macros.
```c++ ```c++
#undef LOG_DOMAIN #undef LOG_DOMAIN
#undef LOG_TAG #undef LOG_TAG
#define LOG_DOMAIN 0x3200 // Service domain. The value ranges from 0xD0000 to 0xDFFFF. #define LOG_DOMAIN 0x3200 // Global domain, which identifies the service domain.
#define LOG_TAG "MY_TAG" #define LOG_TAG "MY_TAG" // Global tag, which identifies the module log tag.
``` ```
3. Print logs. For example, to print INFO logs, use the following code: 3. Print logs. For example, to print ERROR logs, use the following code:
```c++ ```c++
OH_LOG_INFO(LOG_APP, "Failed to visit %{private}s, reason:%{public}d.", url, errno); OH_LOG_ERROR(LOG_APP, "Failed to visit %{private}s, reason:%{public}d.", url, errno);
``` ```
4. View the output log information. 4. View the output log information.
``` ```
12-11 12:21:47.579 2695 2695 I A03200/MY_TAG: Failed to visit <private>, reason:11. 12-11 12:21:47.579 2695 2695 E A03200/MY_TAG: Failed to visit <private>, reason:11.
``` ```
...@@ -87,7 +87,7 @@ The development process consists of the following main steps: ...@@ -87,7 +87,7 @@ The development process consists of the following main steps:
The required model can be downloaded directly or obtained using the model conversion tool. 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 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. 2. Create a context, and set parameters such as the number of runtime threads and device type.
......
...@@ -313,7 +313,7 @@ ...@@ -313,7 +313,7 @@
- [@ohos.systemParameterV9 (System Parameter)](js-apis-system-parameterV9.md) - [@ohos.systemParameterV9 (System Parameter)](js-apis-system-parameterV9.md)
- [@ohos.thermal (Thermal Management)](js-apis-thermal.md) - [@ohos.thermal (Thermal Management)](js-apis-thermal.md)
- [@ohos.update (Update)](js-apis-update.md) - [@ohos.update (Update)](js-apis-update.md)
- [@ohos.usbV9 (USB Management)](js-apis-usb.md) - [@ohos.usbManager (USB Management)](js-apis-usbManager.md)
- [@ohos.vibrator (Vibrator)](js-apis-vibrator.md) - [@ohos.vibrator (Vibrator)](js-apis-vibrator.md)
- Account Management - Account Management
- [@ohos.account.appAccount (App Account Management)](js-apis-appAccount.md) - [@ohos.account.appAccount (App Account Management)](js-apis-appAccount.md)
...@@ -371,7 +371,7 @@ ...@@ -371,7 +371,7 @@
- [@ohos.reminderAgent (Reminder Agent)](js-apis-reminderAgent.md) - [@ohos.reminderAgent (Reminder Agent)](js-apis-reminderAgent.md)
- [@ohos.statfs (statfs)](js-apis-statfs.md) - [@ohos.statfs (statfs)](js-apis-statfs.md)
- [@ohos.systemParameter (System Parameter)](js-apis-system-parameter.md) - [@ohos.systemParameter (System Parameter)](js-apis-system-parameter.md)
- [@ohos.usb (USB Management)](js-apis-usb-deprecated.md) - [@ohos.usbV9 (USB Management)](js-apis-usb.md)
- [@system.app (Application Context)](js-apis-system-app.md) - [@system.app (Application Context)](js-apis-system-app.md)
- [@system.battery (Battery Information)](js-apis-system-battery.md) - [@system.battery (Battery Information)](js-apis-system-battery.md)
- [@system.bluetooth (Bluetooth)](js-apis-system-bluetooth.md) - [@system.bluetooth (Bluetooth)](js-apis-system-bluetooth.md)
......
...@@ -9,7 +9,7 @@ The **AccessibilityExtensionAbility** module provides accessibility extension ca ...@@ -9,7 +9,7 @@ The **AccessibilityExtensionAbility** module provides accessibility extension ca
## Modules to Import ## Modules to Import
```ts ```ts
import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility' import AccessibilityExtensionAbility from '@ohos.application.AccessibilityExtensionAbility';
``` ```
## Attributes ## Attributes
...@@ -31,7 +31,7 @@ Defines an accessibility event. ...@@ -31,7 +31,7 @@ Defines an accessibility event.
| Name | Type | Readable | Writable | Description | | Name | Type | Readable | Writable | Description |
| --------- | ---------------------------------------- | ---- | ---- | ---------- | | --------- | ---------------------------------------- | ---- | ---- | ---------- |
| eventType | [accessibility.EventType](js-apis-accessibility.md#EventType) \| [accessibility.WindowUpdateType](js-apis-accessibility.md#WindowUpdateType) \| [TouchGuideType](#touchguidetype) \| [GestureType](#gesturetype) \| [PageUpdateType](#pageupdatetype) | Yes | No | Event type. | | eventType | [accessibility.EventType](js-apis-accessibility.md#EventType) \| [accessibility.WindowUpdateType](js-apis-accessibility.md#WindowUpdateType) \| [TouchGuideType](#touchguidetype) \| [GestureType](#gesturetype) \| [PageUpdateType](#pageupdatetype) | Yes | No | Event type. |
| target | AccessibilityElement | Yes | No | Target component where the event occurs.| | target | [AccessibilityElement](js-apis-inner-application-accessibilityExtensionContext.md#accessibilityelement9) | Yes | No | Target component where the event occurs.|
| timeStamp | number | Yes | No | Timestamp of the event. | | timeStamp | number | Yes | No | Timestamp of the event. |
## GestureType ## GestureType
...@@ -78,8 +78,8 @@ Enumerates the touch guide event types. ...@@ -78,8 +78,8 @@ Enumerates the touch guide event types.
| Name | Description | | Name | Description |
| ---------- | ------------ | | ---------- | ------------ |
| touchBegin | Start of touch in touch guide mode. | | touchBegin | Start of touch in touch guide mode.|
| touchEnd | End of touch in touch guide mode. | | touchEnd | End of touch in touch guide mode.|
## AccessibilityExtensionAbility.onConnect ## AccessibilityExtensionAbility.onConnect
...@@ -137,7 +137,7 @@ Called when an event that matches the specified bundle and event type occurs. In ...@@ -137,7 +137,7 @@ Called when an event that matches the specified bundle and event type occurs. In
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility { class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
onAccessibilityEvent(event) { onAccessibilityEvent(event) {
console.log('AxExtensionAbility onAccessibilityEvent'); console.log('AxExtensionAbility onAccessibilityEvent');
if (event.eventType == 'click') { if (event.eventType === 'click') {
console.log('AxExtensionAbility onAccessibilityEvent: click'); console.log('AxExtensionAbility onAccessibilityEvent: click');
} }
} }
...@@ -164,7 +164,7 @@ Called when a physical key is pressed. In this API, you can determine whether to ...@@ -164,7 +164,7 @@ Called when a physical key is pressed. In this API, you can determine whether to
class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility { class MyAccessibilityExtensionAbility extends AccessibilityExtensionAbility {
onKeyEvent(keyEvent) { onKeyEvent(keyEvent) {
console.log('AxExtensionAbility onKeyEvent'); console.log('AxExtensionAbility onKeyEvent');
if (keyEvent.keyCode == 22) { if (keyEvent.keyCode === 22) {
console.log('AxExtensionAbility onKeyEvent: intercept 22'); console.log('AxExtensionAbility onKeyEvent: intercept 22');
return true; return true;
} }
......
...@@ -2,9 +2,11 @@ ...@@ -2,9 +2,11 @@
The **batteryInfo** module provides APIs for querying the charger type, battery health status, and battery charging status. The **batteryInfo** module provides APIs for querying the charger type, battery health status, and battery charging status.
> **NOTE**<br> > **NOTE**
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
```js ```js
...@@ -20,18 +22,18 @@ Describes battery information. ...@@ -20,18 +22,18 @@ Describes battery information.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| --------------- | ------------------- | ---- | ---- | ---------------------| | --------------- | ------------------- | ---- | ---- | ---------------------|
| batterySOC | number | Yes | No | Battery state of charge (SoC) of the device, in unit of percentage. | | batterySOC | number | Yes | No | Battery state of charge (SoC) of the device, in unit of percentage. |
| chargingStatus | [BatteryChargeState](#batterychargestate) | Yes | No | Battery charging state of the device. | | chargingStatus | [BatteryChargeState](#batterychargestate) | Yes | No | Battery charging status of the device. |
| healthStatus | [BatteryHealthState](#batteryhealthstate) | Yes | No | Battery health state of the device. | | healthStatus | [BatteryHealthState](#batteryhealthstate) | Yes | No | Battery health status of the device. |
| pluggedType | [BatteryPluggedType](#batterypluggedtype) | Yes | No | Charger type of the device. | | pluggedType | [BatteryPluggedType](#batterypluggedtype) | Yes | No | Charger type of the device. |
| voltage | number | Yes | No | Battery voltage of the device, in unit of microvolt. | | voltage | number | Yes | No | Battery voltage of the device, in unit of microvolt. |
| technology | string | Yes | No | Battery technology of the device. | | technology | string | Yes | No | Battery technology of the device. |
| batteryTemperature | number | Yes | No | Battery temperature of the device, in unit of 0.1°C. | | batteryTemperature | number | Yes | No | Battery temperature of the device, in unit of 0.1°C. |
| isBatteryPresent<sup>7+</sup> | boolean | Yes | No | Whether the battery is supported or present. | | isBatteryPresent<sup>7+</sup> | boolean | Yes | No | Whether the battery is supported or present. |
| batteryCapacityLevel<sup>9+</sup> | [BatteryCapacityLevel](#batterycapacitylevel9) | Yes | No | Battery level of the device. | | batteryCapacityLevel<sup>9+</sup> | [BatteryCapacityLevel](#batterycapacitylevel9) | Yes | No | Battery level of the device. |
| estimatedRemainingChargeTime<sup>9+</sup> | number | Yes | No | Estimated time for fully charging the current device, in unit of milliseconds. | | estimatedRemainingChargeTime<sup>9+</sup> | number | Yes | No | Estimated time for fully charging the current device, in unit of milliseconds. **System API**: This is a system API. |
| totalEnergy<sup>9+</sup> | number | Yes | No | Total battery capacity of the device, in unit of mAh. This is a system API. | | totalEnergy<sup>9+</sup> | number | Yes | No | Total battery capacity of the device, in unit of mAh. **System API**: This is a system API. |
| nowCurrent<sup>9+</sup> | number | Yes | No | Battery current of the device, in unit of mA. This is a system API. | | nowCurrent<sup>9+</sup> | number | Yes | No | Battery current of the device, in unit of mA. **System API**: This is a system API. |
| remainingEnergy<sup>9+</sup> | number | Yes | No | Remaining battery capacity of the device, in unit of mAh. This is a system API.| | remainingEnergy<sup>9+</sup> | number | Yes | No | Remaining battery capacity of the device, in unit of mAh. **System API**: This is a system API.|
## BatteryPluggedType ## BatteryPluggedType
...@@ -41,10 +43,10 @@ Enumerates charger types. ...@@ -41,10 +43,10 @@ Enumerates charger types.
| Name | Value | Description | | Name | Value | Description |
| -------- | ---- | ----------------- | | -------- | ---- | ----------------- |
| NONE | 0 | Unknown type | | NONE | 0 | Unknown charger type. |
| AC | 1 | AC charger| | AC | 1 | AC charger.|
| USB | 2 | USB charger | | USB | 2 | USB charger. |
| WIRELESS | 3 | Wireless charger| | WIRELESS | 3 | Wireless charger.|
## BatteryChargeState ## BatteryChargeState
...@@ -82,14 +84,15 @@ Enumerates battery levels. ...@@ -82,14 +84,15 @@ Enumerates battery levels.
| Name | Value| Description | | Name | Value| Description |
| -------------- | ------ | ---------------------------- | | -------------- | ------ | ---------------------------- |
| LEVEL_NONE | 0 | Unknown battery level. |
| LEVEL_FULL | 1 | Full battery level. | | LEVEL_FULL | 1 | Full battery level. |
| LEVEL_HIGH | 2 | High battery level. | | LEVEL_HIGH | 2 | High battery level. |
| LEVEL_NORMAL | 3 | Normal battery level.| | LEVEL_NORMAL | 3 | Normal battery level.|
| LEVEL_LOW | 4 | Low battery level. | | LEVEL_LOW | 4 | Low battery level. |
| LEVEL_CRITICAL | 5 | Ultra-low battery level.| | LEVEL_WARNING | 5 | Alarm battery level.|
| LEVEL_CRITICAL | 6 | Ultra-low battery level.|
| LEVEL_SHUTDOWN | 7 | Power-down battery level.|
## CommonEventBatteryChangedCode<sup>9+</sup> ## CommonEventBatteryChangedKey<sup>9+</sup>
Enumerates keys for querying the additional information about the **COMMON_EVENT_BATTERY_CHANGED** event. Enumerates keys for querying the additional information about the **COMMON_EVENT_BATTERY_CHANGED** event.
...@@ -97,14 +100,12 @@ Enumerates keys for querying the additional information about the **COMMON_EVENT ...@@ -97,14 +100,12 @@ Enumerates keys for querying the additional information about the **COMMON_EVENT
| Name | Value| Description | | Name | Value| Description |
| -------------------- | ------ | -------------------------------------------------- | | -------------------- | ------ | -------------------------------------------------- |
| EXTRA_SOC | 0 | Remaining battery level in percentage. | | EXTRA_SOC | "soc" | Remaining battery level in percentage. |
| EXTRA_VOLTAGE | 1 | Battery voltage of the device. | | EXTRA_CHARGE_STATE | "chargeState" | Battery charging status of the device. |
| EXTRA_TEMPERATURE | 2 | Battery temperature of the device. | | EXTRA_HEALTH_STATE | "healthState" | Battery health status of the device. |
| EXTRA_HEALTH_STATE | 3 | Battery health status of the device. | | EXTRA_PLUGGED_TYPE | "pluggedType" | Type of the charger connected to the device. |
| EXTRA_PLUGGED_TYPE | 4 | Type of the charger connected to the device. | | EXTRA_VOLTAGE | "voltage" | Battery voltage of the device. |
| EXTRA_MAX_CURRENT | 5 | Maximum battery current of the device. | | EXTRA_TECHNOLOGY | "technology" | Battery technology of the device. |
| EXTRA_MAX_VOLTAGE | 6 | Maximum battery voltage of the device. | | EXTRA_TEMPERATURE | "temperature" | Battery temperature of the device. |
| EXTRA_CHARGE_STATE | 7 | Battery charging status of the device. | | EXTRA_PRESENT | "present" | Whether the battery is supported by the device or installed.|
| EXTRA_CHARGE_COUNTER | 8 | Number of battery charging times of the device. | | EXTRA_CAPACITY_LEVEL | "capacityLevel" | Battery level of the device. |
| EXTRA_PRESENT | 9 | Whether the battery is supported by the device or installed.|
| EXTRA_TECHNOLOGY | 10 | Battery technology of the device. |
...@@ -722,7 +722,7 @@ Subscribes to service status changes. ...@@ -722,7 +722,7 @@ Subscribes to service status changes.
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------------- | -------------------- | ---- | ------------------------------------------------------------ | | ------------- | -------------------- | ---- | ------------------------------------------------------------ |
| event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates a service status change event.| | event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates a service status change event.|
| deathCallback | Callback&lt;void&gt; | Yes | Callback invoked to service status changes. | | deathCallback | Callback&lt;void&gt; | Yes | Callback invoked to return service status changes. |
**Example** **Example**
...@@ -2847,7 +2847,7 @@ try { ...@@ -2847,7 +2847,7 @@ try {
### get ### get
get(key: string, callback: AsyncCallback<boolean | string| number | Uint8Array>): void get(key: string, callback: AsyncCallback&lt;boolean | string | number | Uint8Array&gt;): void
Obtains the value of the specified key. This API uses an asynchronous callback to return the result. Obtains the value of the specified key. This API uses an asynchronous callback to return the result.
...@@ -2898,7 +2898,7 @@ try { ...@@ -2898,7 +2898,7 @@ try {
### get ### get
get(key: string): Promise&lt;boolean | string| number | Uint8Array&gt; get(key: string): Promise&lt;boolean | string | number | Uint8Array&gt;
Obtains the value of the specified key. This API uses a promise to return the result. Obtains the value of the specified key. This API uses a promise to return the result.
...@@ -4849,7 +4849,7 @@ Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkv ...@@ -4849,7 +4849,7 @@ Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkv
### get ### get
get(key: string, callback: AsyncCallback<boolean | string| number | Uint8Array>): void get(key: string, callback: AsyncCallback&lt;boolean | string | number | Uint8Array&gt;): void
Obtains the value of the specified key for this device. This API uses an asynchronous callback to return the result. Obtains the value of the specified key for this device. This API uses an asynchronous callback to return the result.
...@@ -4900,7 +4900,7 @@ try { ...@@ -4900,7 +4900,7 @@ try {
### get ### get
get(key: string): Promise&lt;boolean | string| number | Uint8Array&gt; get(key: string): Promise&lt;boolean | string | number | Uint8Array&gt;
Obtains the value of the specified key for this device. This API uses a promise to return the result. Obtains the value of the specified key for this device. This API uses a promise to return the result.
...@@ -4952,7 +4952,7 @@ try { ...@@ -4952,7 +4952,7 @@ try {
### get ### get
get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean|string|number|Uint8Array&gt;): void get(deviceId: string, key: string, callback: AsyncCallback&lt;boolean | string | number | Uint8Array&gt;): void
Obtains a string value that matches the specified device ID and key. This API uses an asynchronous callback to return the result. Obtains a string value that matches the specified device ID and key. This API uses an asynchronous callback to return the result.
...@@ -5004,7 +5004,7 @@ try { ...@@ -5004,7 +5004,7 @@ try {
### get ### get
get(deviceId: string, key: string): Promise&lt;boolean|string|number|Uint8Array&gt; get(deviceId: string, key: string): Promise&lt;boolean | string | number | Uint8Array&gt;
Obtains a string value that matches the specified device ID and key. This API uses a promise to return the result. Obtains a string value that matches the specified device ID and key. This API uses a promise to return the result.
......
...@@ -35,7 +35,7 @@ Enables a device administrator application based on the specified bundle name an ...@@ -35,7 +35,7 @@ Enables a device administrator application based on the specified bundle name an
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | --------------------------------------------------------------- | | ------- | --------------------------------------------------------------- |
...@@ -87,7 +87,7 @@ Enables a device administrator application for the specified user based on the s ...@@ -87,7 +87,7 @@ Enables a device administrator application for the specified user based on the s
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | --------------------------------------------------------------- | | ------- | --------------------------------------------------------------- |
...@@ -144,7 +144,7 @@ Enables a device administrator application based on the specified bundle name an ...@@ -144,7 +144,7 @@ Enables a device administrator application based on the specified bundle name an
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | --------------------------------------------------------------- | | ------- | --------------------------------------------------------------- |
...@@ -190,7 +190,7 @@ Disables a device common administrator application based on the specified bundle ...@@ -190,7 +190,7 @@ Disables a device common administrator application based on the specified bundle
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------------------- | | ------- | ----------------------------------------------------------------- |
...@@ -234,7 +234,7 @@ Disables a device common administrator application for the specified user based ...@@ -234,7 +234,7 @@ Disables a device common administrator application for the specified user based
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------------------- | | ------- | ----------------------------------------------------------------- |
...@@ -283,7 +283,7 @@ Disables a device common administrator application based on the specified bundle ...@@ -283,7 +283,7 @@ Disables a device common administrator application based on the specified bundle
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------------------- | | ------- | ----------------------------------------------------------------- |
...@@ -322,7 +322,7 @@ Disables a device super administrator application based on the specified bundle ...@@ -322,7 +322,7 @@ Disables a device super administrator application based on the specified bundle
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------------------- | | ------- | ----------------------------------------------------------------- |
...@@ -367,7 +367,7 @@ Disables a device super administrator application based on the specified bundle ...@@ -367,7 +367,7 @@ Disables a device super administrator application based on the specified bundle
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------------------- | | ------- | ----------------------------------------------------------------- |
...@@ -571,7 +571,7 @@ Sets the enterprise information of a device administrator application. This API ...@@ -571,7 +571,7 @@ Sets the enterprise information of a device administrator application. This API
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------------------------- |
...@@ -624,7 +624,7 @@ Sets the enterprise information of a device administrator application. This API ...@@ -624,7 +624,7 @@ Sets the enterprise information of a device administrator application. This API
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------------------------- |
...@@ -665,7 +665,7 @@ Obtains the enterprise information of a device administrator application. This A ...@@ -665,7 +665,7 @@ Obtains the enterprise information of a device administrator application. This A
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------------------------- |
...@@ -712,7 +712,7 @@ Obtains the enterprise information of a device administrator application. This A ...@@ -712,7 +712,7 @@ Obtains the enterprise information of a device administrator application. This A
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------------------------- |
...@@ -755,7 +755,7 @@ Subscribes to system management events. This API uses an asynchronous callback t ...@@ -755,7 +755,7 @@ Subscribes to system management events. This API uses an asynchronous callback t
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
|ID| Error Message | |ID| Error Message |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------------------------- |
...@@ -804,7 +804,7 @@ Subscribes to system management events. This API uses a promise to return the re ...@@ -804,7 +804,7 @@ Subscribes to system management events. This API uses a promise to return the re
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------------------------- |
...@@ -847,7 +847,7 @@ Unsubscribes from system management events. This API uses an asynchronous callba ...@@ -847,7 +847,7 @@ Unsubscribes from system management events. This API uses an asynchronous callba
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------------------------- |
...@@ -896,7 +896,7 @@ Unsubscribes from system management events. This API uses an asynchronous callba ...@@ -896,7 +896,7 @@ Unsubscribes from system management events. This API uses an asynchronous callba
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ----------------------------------------------------- | | ------- | ----------------------------------------------------- |
......
...@@ -34,7 +34,7 @@ Sets the system time. This API uses an asynchronous callback to return the resul ...@@ -34,7 +34,7 @@ Sets the system time. This API uses an asynchronous callback to return the resul
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
...@@ -82,7 +82,7 @@ Sets the system time. This API uses a promise to return the result. ...@@ -82,7 +82,7 @@ Sets the system time. This API uses a promise to return the result.
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
......
# @ohos.enterprise.deviceControl (Device Control Management)
The **deviceControl** module provides APIs for device control, which can only be called by device administrator applications.
> **NOTE**
>
> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```js
import deviceControl from '@ohos.enterprise.deviceControl'
```
## deviceControl.resetFactory
resetFactory(admin: Want, callback: AsyncCallback\<void>): void
Restores factory settings. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESET_DEVICE
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
| callback | AsyncCallback\<void> | Yes| Callback used to return the result. If the setting is successful, **err** is **null**. Otherwise, **err** is an error object.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example:**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
deviceControl.resetFactory(wantTemp, (error) => {
if (error) {
console.log("error code:" + error.code + " error message:" + error.message);
}
})
```
## deviceControl.resetFactory
resetFactory(admin: Want): Promise\<void>
Restores factory settings. This API uses a promise to return the result.
**Required permissions**: ohos.permission.ENTERPRISE_RESET_DEVICE
**System capability**: SystemCapability.Customization.EnterpriseDeviceManager
**System API**: This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ----------------------------------- | ---- | ------- |
| admin | [Want](js-apis-app-ability-want.md) | Yes | Device administrator application.|
**Return value**
| Type | Description |
| ----- | ----------------------------------- |
| Promise\<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message |
| ------- | ---------------------------------------------------------------------------- |
| 9200001 | the application is not an administrator of the device. |
| 9200002 | the administrator application does not have permission to manage the device. |
**Example:**
```js
let wantTemp = {
bundleName: "bundleName",
abilityName: "abilityName",
};
deviceControl.resetFactory(wantTemp).then(() => {
}).catch((error) => {
console.log("error code:" + error.code + " error message:" + error.message);
})
```
...@@ -33,7 +33,7 @@ Obtains the device serial number. This API uses an asynchronous callback to retu ...@@ -33,7 +33,7 @@ Obtains the device serial number. This API uses an asynchronous callback to retu
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
...@@ -82,7 +82,7 @@ Obtains the device serial number. This API uses a promise to return the result. ...@@ -82,7 +82,7 @@ Obtains the device serial number. This API uses a promise to return the result.
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
...@@ -124,7 +124,7 @@ Obtains the device version number. This API uses an asynchronous callback to ret ...@@ -124,7 +124,7 @@ Obtains the device version number. This API uses an asynchronous callback to ret
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
...@@ -173,7 +173,7 @@ Obtains the device version number. This API uses a promise to return the result. ...@@ -173,7 +173,7 @@ Obtains the device version number. This API uses a promise to return the result.
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
...@@ -215,7 +215,7 @@ Obtains the device name. This API uses an asynchronous callback to return the re ...@@ -215,7 +215,7 @@ Obtains the device name. This API uses an asynchronous callback to return the re
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
...@@ -264,7 +264,7 @@ Obtains the device name. This API uses a promise to return the result. ...@@ -264,7 +264,7 @@ Obtains the device name. This API uses a promise to return the result.
**Error codes** **Error codes**
For details about the following error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md). For details about the error codes, see [Enterprise Device Management Error Codes](../errorcodes/errorcode-enterpriseDeviceManager.md).
| ID| Error Message | | ID| Error Message |
| ------- | ---------------------------------------------------------------------------- | | ------- | ---------------------------------------------------------------------------- |
......
...@@ -17,7 +17,7 @@ import fileAccess from '@ohos.file.fileAccess'; ...@@ -17,7 +17,7 @@ import fileAccess from '@ohos.file.fileAccess';
getFileAccessAbilityInfo( ) : Promise&lt;Array&lt;Want&gt;&gt; getFileAccessAbilityInfo( ) : Promise&lt;Array&lt;Want&gt;&gt;
Obtains information about all wants with **extension** set to **fileAcesss** in the system. A want is a basic communication component used to start services. This API uses a promise to return the result. Obtains information about all wants with **extension** set to **fileAccess** in the system. A want is a basic communication component used to start services. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -25,9 +25,9 @@ Obtains information about all wants with **extension** set to **fileAcesss** in ...@@ -25,9 +25,9 @@ Obtains information about all wants with **extension** set to **fileAcesss** in
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.| | Promise&lt;Array&lt;Want&gt;&gt; | Promise used to return the **want** information obtained.|
**Example** **Example**
...@@ -47,7 +47,7 @@ Obtains information about all wants with **extension** set to **fileAcesss** in ...@@ -47,7 +47,7 @@ Obtains information about all wants with **extension** set to **fileAcesss** in
getFileAccessAbilityInfo(callback: AsyncCallback&lt;Array&lt;Want&gt;&gt;): void; getFileAccessAbilityInfo(callback: AsyncCallback&lt;Array&lt;Want&gt;&gt;): void;
Obtains information about all wants with **extension** set to **fileAcesss** in the system. A want is a basic communication component used to start services. This API uses an asynchronous callback to return the result. Obtains information about all wants with **extension** set to **fileAccess** in the system. A want is a basic communication component used to start services. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -55,9 +55,9 @@ Obtains information about all wants with **extension** set to **fileAcesss** in ...@@ -55,9 +55,9 @@ Obtains information about all wants with **extension** set to **fileAcesss** in
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.| | callback | AsyncCallback&lt;Array&lt;Want&gt;&gt; | Yes| Promise used to return the **want** information obtained.|
**Example** **Example**
...@@ -89,16 +89,16 @@ Synchronously creates a **Helper** object to connect to the specified wants. The ...@@ -89,16 +89,16 @@ Synchronously creates a **Helper** object to connect to the specified wants. The
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.| | context | Context | Yes| Context of the ability.|
| wants | Array&lt;Want&gt; | Yes| Wants to connect.| | wants | Array&lt;Want&gt; | Yes| Wants to connect.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| FileAccessHelper | **Helper** object created.| | FileAccessHelper | **Helper** object created.|
**Example** **Example**
...@@ -114,7 +114,7 @@ Synchronously creates a **Helper** object to connect to the specified wants. The ...@@ -114,7 +114,7 @@ Synchronously creates a **Helper** object to connect to the specified wants. The
}, },
] ]
try { try {
// this.context is passed by MainAbility. // this.context is passed by EntryAbility.
fileAccessHelper = fileAccess.createFileAccessHelper(this.context, wantInfos); fileAccessHelper = fileAccess.createFileAccessHelper(this.context, wantInfos);
if (!fileAccessHelper) if (!fileAccessHelper)
console.error("createFileAccessHelper interface returns an undefined object"); console.error("createFileAccessHelper interface returns an undefined object");
...@@ -136,15 +136,15 @@ Synchronously creates a **Helper** object to connect to all file management serv ...@@ -136,15 +136,15 @@ Synchronously creates a **Helper** object to connect to all file management serv
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| context | Context | Yes| Context of the ability.| | context | Context | Yes| Context of the ability.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| FileAccessHelper | **Helper** object created.| | FileAccessHelper | **Helper** object created.|
**Example** **Example**
...@@ -153,7 +153,7 @@ Synchronously creates a **Helper** object to connect to all file management serv ...@@ -153,7 +153,7 @@ Synchronously creates a **Helper** object to connect to all file management serv
let fileAccesssHelperAllServer = null; let fileAccesssHelperAllServer = null;
// Create a Helper object to interact with all file management services configured with fileAccess in the system. // Create a Helper object to interact with all file management services configured with fileAccess in the system.
try { try {
// this.context is passed by MainAbility. // this.context is passed by EntryAbility.
fileAccesssHelperAllServer = fileAccess.createFileAccessHelper(this.context); fileAccesssHelperAllServer = fileAccess.createFileAccessHelper(this.context);
if (!fileAccesssHelperAllServer) if (!fileAccesssHelperAllServer)
console.error("createFileAccessHelper interface returns an undefined object"); console.error("createFileAccessHelper interface returns an undefined object");
...@@ -167,8 +167,7 @@ Synchronously creates a **Helper** object to connect to all file management serv ...@@ -167,8 +167,7 @@ Synchronously creates a **Helper** object to connect to all file management serv
getRoots( ) : Promise&lt;RootIterator&gt; getRoots( ) : Promise&lt;RootIterator&gt;
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses a promise to return a **RootIterator** object, which Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses a promise to return a **RootIterator** object, which returns [RootInfo](#rootinfo) by using [next()](#rootiteratornext).
returns [RootInfo](#rootinfo) by using [next()](#rootiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -176,9 +175,9 @@ returns [RootInfo](#rootinfo) by using [next()](#rootiteratornext). ...@@ -176,9 +175,9 @@ returns [RootInfo](#rootinfo) by using [next()](#rootiteratornext).
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.| | Promise&lt;RootIterator&gt; | Promise used to return the **RootIterator** object obtained.|
**Example** **Example**
...@@ -211,8 +210,7 @@ returns [RootInfo](#rootinfo) by using [next()](#rootiteratornext). ...@@ -211,8 +210,7 @@ returns [RootInfo](#rootinfo) by using [next()](#rootiteratornext).
getRoots(callback:AsyncCallback&lt;RootIterator&gt;) : void; getRoots(callback:AsyncCallback&lt;RootIterator&gt;) : void;
Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result. Obtains information about the device root nodes of the file management service type connected to the **Helper** object. This API uses an asynchronous callback to return the result. The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext).
The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) through [next()](#rootiteratornext).
**System capability**: SystemCapability.FileManagement.UserFileService **System capability**: SystemCapability.FileManagement.UserFileService
...@@ -220,9 +218,9 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo) ...@@ -220,9 +218,9 @@ The callback has a **RootIterator** object, which returns [RootInfo](#rootinfo)
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.| | callback | AsyncCallback&lt;RootIterator&gt; | Yes| Promise used to return the **RootIterator** object obtained.|
**Example** **Example**
...@@ -263,16 +261,16 @@ Synchronously obtains the **FileIterator** object of the first-level files (file ...@@ -263,16 +261,16 @@ Synchronously obtains the **FileIterator** object of the first-level files (file
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | -- | -- | | --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. | | filter | Filter | No| **Filter** object. |
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| FileIterator | **FileIterator** object obtained.| | FileIterator | **FileIterator** object obtained.|
**Example** **Example**
...@@ -314,15 +312,15 @@ Recursively obtains the **FileIterator** object of the files matching the condit ...@@ -314,15 +312,15 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | -- | -- | | --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. | | filter | Filter | No| **Filter** object. |
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| FileIterator | **FileIterator** object obtained.| | FileIterator | **FileIterator** object obtained.|
**Example** **Example**
...@@ -364,15 +362,15 @@ Synchronously obtains the **FileIterator** object of the next-level files (file ...@@ -364,15 +362,15 @@ Synchronously obtains the **FileIterator** object of the next-level files (file
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | -- | -- | | --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. | | filter | Filter | No| **Filter** object. |
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| FileIterator | **FileIterator** object obtained.| | FileIterator | **FileIterator** object obtained.|
**Example** **Example**
...@@ -414,16 +412,16 @@ Recursively obtains the **FileIterator** object of the files matching the condit ...@@ -414,16 +412,16 @@ Recursively obtains the **FileIterator** object of the files matching the condit
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | -- | -- | | --- | --- | -- | -- |
| filter | Filter | No| **Filter** object. | | filter | Filter | No| **Filter** object. |
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| FileIterator | **FileIterator** object obtained.| | FileIterator | **FileIterator** object obtained.|
**Example** **Example**
...@@ -465,10 +463,10 @@ Creates a file in a directory. This API uses a promise to return the result. ...@@ -465,10 +463,10 @@ Creates a file in a directory. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.| | uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.| | displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
**Return value** **Return value**
...@@ -510,11 +508,11 @@ Creates a file in a directory. This API uses an asynchronous callback to return ...@@ -510,11 +508,11 @@ Creates a file in a directory. This API uses an asynchronous callback to return
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| uri | string | Yes| URI of the parent directory for the file to create.| | uri | string | Yes| URI of the parent directory for the file to create.|
| displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.| | displayName | string | Yes| Name of the file to create. By default, the name of a local file must contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.| | callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file created.|
**Example** **Example**
...@@ -550,10 +548,10 @@ Creates a folder in a directory. This API uses a promise to return the result. ...@@ -550,10 +548,10 @@ Creates a folder in a directory. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the folder to create.| | parentUri | string | Yes| URI of the parent directory for the folder to create.|
| displayName | string | Yes| Name of the folder to create.| | displayName | string | Yes| Name of the folder to create.|
**Return value** **Return value**
...@@ -595,11 +593,11 @@ Creates a folder in a directory. This API uses an asynchronous callback to retur ...@@ -595,11 +593,11 @@ Creates a folder in a directory. This API uses an asynchronous callback to retur
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| parentUri | string | Yes| URI of the parent directory for the folder to create.| | parentUri | string | Yes| URI of the parent directory for the folder to create.|
| displayName | string | Yes| Name of the folder to create.| | displayName | string | Yes| Name of the folder to create.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the folder created.| | callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the folder created.|
**Example** **Example**
...@@ -635,16 +633,16 @@ Opens a file. This API uses a promise to return the result. ...@@ -635,16 +633,16 @@ Opens a file. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.| | uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.| | flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| --- | -- | | --- | -- |
| Promise&lt;number&gt; | Promise used to return the handle to the file opened.| | Promise&lt;number&gt; | Promise used to return the file descriptor of the file opened.|
**Example** **Example**
...@@ -673,11 +671,11 @@ Opens a file. This API uses an asynchronous callback to return the result. ...@@ -673,11 +671,11 @@ Opens a file. This API uses an asynchronous callback to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| uri | string | Yes| URI of the file to open.| | uri | string | Yes| URI of the file to open.|
| flags | [OPENFLAGS](#openflags) | Yes| File open mode.| | flags | [OPENFLAGS](#openflags) | Yes| File open mode.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the handle to the file opened.| | callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the file descriptor of the file opened.|
**Example** **Example**
...@@ -712,9 +710,9 @@ Deletes a file or folder. This API uses a promise to return the result. ...@@ -712,9 +710,9 @@ Deletes a file or folder. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to delete.| | uri | string | Yes| URI of the file or folder to delete.|
**Return value** **Return value**
...@@ -751,10 +749,10 @@ Deletes a file or folder. This API uses an asynchronous callback to return the r ...@@ -751,10 +749,10 @@ Deletes a file or folder. This API uses an asynchronous callback to return the r
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to delete.| | uri | string | Yes| URI of the file or folder to delete.|
| callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.| | callback | AsyncCallback&lt;number&gt; | Yes| Promise used to return the result.|
**Example** **Example**
...@@ -789,10 +787,10 @@ Moves a file or folder. This API uses a promise to return the result. ...@@ -789,10 +787,10 @@ Moves a file or folder. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or folder to move.| | sourceFile | string | Yes| URI of the file or folder to move.|
| destFile | string | Yes| URI of the folder to which the file or folder will be moved.| | destFile | string | Yes| URI of the folder to which the file or folder will be moved.|
**Return value** **Return value**
...@@ -829,11 +827,11 @@ Moves a file or folder. This API uses an asynchronous callback to return the res ...@@ -829,11 +827,11 @@ Moves a file or folder. This API uses an asynchronous callback to return the res
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| sourceFile | string | Yes| URI of the file or folder to move.| | sourceFile | string | Yes| URI of the file or folder to move.|
| destFile | string | Yes| URI of the folder to which the file or folder will be moved.| | destFile | string | Yes| URI of the folder to which the file or folder will be moved.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or folder in the destination directory.| | callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the file or folder in the destination directory.|
**Example** **Example**
...@@ -869,10 +867,10 @@ Renames a file or folder. This API uses a promise to return the result. ...@@ -869,10 +867,10 @@ Renames a file or folder. This API uses a promise to return the result.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to rename.| | uri | string | Yes| URI of the file or folder to rename.|
| displayName | string | Yes| New name of the file or folder, which can contain the file name extension.| | displayName | string | Yes| New name of the file or folder, which can contain the file name extension.|
**Return value** **Return value**
...@@ -908,11 +906,11 @@ Renames a file or folder. This API uses an asynchronous callback to return the r ...@@ -908,11 +906,11 @@ Renames a file or folder. This API uses an asynchronous callback to return the r
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| uri | string | Yes| URI of the file or folder to rename.| | uri | string | Yes| URI of the file or folder to rename.|
| displayName | string | Yes| New name of the file or folder, which can contain the file name extension.| | displayName | string | Yes| New name of the file or folder, which can contain the file name extension.|
| callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or folder.| | callback | AsyncCallback&lt;string&gt; | Yes| Promise used to return the URI of the renamed file or folder.|
**Example** **Example**
...@@ -947,9 +945,9 @@ Checks whether a file or folder exists. This API uses a promise to return the re ...@@ -947,9 +945,9 @@ Checks whether a file or folder exists. This API uses a promise to return the re
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or folder.| | sourceFileUri | string | Yes| URI of the file or folder.|
**Return value** **Return value**
...@@ -988,10 +986,10 @@ Checks whether a file or folder exists. This API uses an asynchronous callback t ...@@ -988,10 +986,10 @@ Checks whether a file or folder exists. This API uses an asynchronous callback t
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| --- | --- | --- | -- | | --- | --- | --- | -- |
| sourceFileUri | string | Yes| URI of the file or folder.| | sourceFileUri | string | Yes| URI of the file or folder.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Promise used to return the result.|
**Example** **Example**
......
...@@ -278,7 +278,7 @@ Obtains the mouse pointer style. This API uses an asynchronous callback to retur ...@@ -278,7 +278,7 @@ Obtains the mouse pointer style. This API uses an asynchronous callback to retur
import window from '@ohos.window'; import window from '@ohos.window';
window.getTopWindow((error, win) => { window.getTopWindow((error, win) => {
win.getProperties((error, properties) => { win.getWindowProperties((error, properties) => {
let windowId = properties.id; let windowId = properties.id;
if (windowId < 0) { if (windowId < 0) {
console.log(`Invalid windowId`); console.log(`Invalid windowId`);
...@@ -321,7 +321,7 @@ Obtains the mouse pointer style. This API uses a promise to return the result. ...@@ -321,7 +321,7 @@ Obtains the mouse pointer style. This API uses a promise to return the result.
import window from '@ohos.window'; import window from '@ohos.window';
window.getTopWindow((error, win) => { window.getTopWindow((error, win) => {
win.getProperties((error, properties) => { win.getWindowProperties((error, properties) => {
let windowId = properties.id; let windowId = properties.id;
if (windowId < 0) { if (windowId < 0) {
console.log(`Invalid windowId`); console.log(`Invalid windowId`);
...@@ -360,7 +360,7 @@ Sets the mouse pointer style. This API uses an asynchronous callback to return t ...@@ -360,7 +360,7 @@ Sets the mouse pointer style. This API uses an asynchronous callback to return t
import window from '@ohos.window'; import window from '@ohos.window';
window.getTopWindow((error, win) => { window.getTopWindow((error, win) => {
win.getProperties((error, properties) => { win.getWindowProperties((error, properties) => {
let windowId = properties.id; let windowId = properties.id;
if (windowId < 0) { if (windowId < 0) {
console.log(`Invalid windowId`); console.log(`Invalid windowId`);
...@@ -398,7 +398,7 @@ Sets the mouse pointer style. This API uses a promise to return the result. ...@@ -398,7 +398,7 @@ Sets the mouse pointer style. This API uses a promise to return the result.
import window from '@ohos.window'; import window from '@ohos.window';
window.getTopWindow((error, win) => { window.getTopWindow((error, win) => {
win.getProperties((error, properties) => { win.getWindowProperties((error, properties) => {
let windowId = properties.id; let windowId = properties.id;
if (windowId < 0) { if (windowId < 0) {
console.log(`Invalid windowId`); console.log(`Invalid windowId`);
......
...@@ -286,95 +286,6 @@ Uploads files. This API uses an asynchronous callback to return the result. ...@@ -286,95 +286,6 @@ Uploads files. This API uses an asynchronous callback to return the result.
}); });
``` ```
## request.upload<sup>(deprecated)</sup>
upload(context: BaseContext, config: UploadConfig): Promise&lt;UploadTask&gt;
Uploads files. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 9 and is deprecated since API version 9. You are advised to use [request.uploadFile<sup>9+</sup>](#requestuploadfile9).
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | [BaseContext](js-apis-inner-application-baseContext.md) | Yes| Application-based context.|
| config | [UploadConfig](#uploadconfig) | Yes| Upload configurations.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[UploadTask](#uploadtask)&gt; | Promise used to return the **UploadTask** object.|
**Example**
```js
let uploadTask;
let uploadConfig = {
url: 'http://patch',
header: { key1: "value1", key2: "value2" },
method: "POST",
files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }],
data: [{ name: "name123", value: "123" }],
};
request.upload(globalThis.abilityContext, uploadConfig).then((data) => {
uploadTask = data;
}).catch((err) => {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
});
```
## request.upload<sup>(deprecated)</sup>
upload(context: BaseContext, config: UploadConfig, callback: AsyncCallback&lt;UploadTask&gt;): void
Uploads files. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [request.uploadFile<sup>9+</sup>](#requestuploadfile9-1).
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Upload
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | [BaseContext](js-apis-inner-application-baseContext.md) | Yes| Application-based context.|
| config | [UploadConfig](#uploadconfig) | Yes| Upload configurations.|
| callback | AsyncCallback&lt;[UploadTask](#uploadtask)&gt; | Yes| Callback used to return the **UploadTask** object.|
**Example**
```js
let uploadTask;
let uploadConfig = {
url: 'http://patch',
header: { key1: "value1", key2: "value2" },
method: "POST",
files: [{ filename: "test", name: "test", uri: "internal://cache/test.jpg", type: "jpg" }],
data: [{ name: "name123", value: "123" }],
};
request.upload(globalThis.abilityContext, uploadConfig, (err, data) => {
if (err) {
console.error('Failed to request the upload. Cause: ' + JSON.stringify(err));
return;
}
uploadTask = data;
});
```
## UploadTask ## UploadTask
Implements file uploads. Before using any APIs of this class, you must obtain an **UploadTask** object through [request.uploadFile<sup>9+</sup>](#requestuploadfile9) in promise mode or [request.uploadFile<sup>9+</sup>](#requestuploadfile9-1) in callback mode. Implements file uploads. Before using any APIs of this class, you must obtain an **UploadTask** object through [request.uploadFile<sup>9+</sup>](#requestuploadfile9) in promise mode or [request.uploadFile<sup>9+</sup>](#requestuploadfile9-1) in callback mode.
...@@ -398,7 +309,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return ...@@ -398,7 +309,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
| type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (upload progress).| | type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (upload progress).|
| callback | function | Yes| Callback for the upload progress event.| | callback | function | Yes| Callback for the upload progress event.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -432,7 +343,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return ...@@ -432,7 +343,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
| type | string | Yes| Type of the event to subscribe to. The value is **'headerReceive'** (response header).| | type | string | Yes| Type of the event to subscribe to. The value is **'headerReceive'** (response header).|
| callback | function | Yes| Callback for the HTTP Response Header event.| | callback | function | Yes| Callback for the HTTP Response Header event.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -465,7 +376,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return ...@@ -465,7 +376,7 @@ Subscribes to an upload event. This API uses an asynchronous callback to return
| type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.| | type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.|
| callback | Callback&lt;Array&lt;TaskState&gt;&gt; | Yes| Callback used to return the result.| | callback | Callback&lt;Array&lt;TaskState&gt;&gt; | Yes| Callback used to return the result.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -507,7 +418,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret ...@@ -507,7 +418,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret
| type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (upload progress).| | type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (upload progress).|
| callback | function | No| Callback for the upload progress event.| | callback | function | No| Callback for the upload progress event.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -541,7 +452,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret ...@@ -541,7 +452,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret
| type | string | Yes| Type of the event to unsubscribe from. The value is **'headerReceive'** (response header).| | type | string | Yes| Type of the event to unsubscribe from. The value is **'headerReceive'** (response header).|
| callback | function | No| Callback for the HTTP Response Header event.| | callback | function | No| Callback for the HTTP Response Header event.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -573,7 +484,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret ...@@ -573,7 +484,7 @@ Unsubscribes from an upload event. This API uses an asynchronous callback to ret
| type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.| | type | string | Yes| Type of the event to subscribe to. The value **'complete'** means the upload completion event, and **'fail'** means the upload failure event.|
| callback | Callback&lt;Array&lt;TaskState&gt;&gt; | No| Callback used to return the result.| | callback | Callback&lt;Array&lt;TaskState&gt;&gt; | No| Callback used to return the result.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -952,82 +863,6 @@ Downloads files. This API uses an asynchronous callback to return the result. ...@@ -952,82 +863,6 @@ Downloads files. This API uses an asynchronous callback to return the result.
}); });
``` ```
## request.download<sup>(deprecated)</sup>
download(context: BaseContext, config: DownloadConfig): Promise&lt;DownloadTask&gt;
Downloads files. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 9 and is deprecated since API version 9. You are advised to use [request.downloadFile<sup>9+</sup>](#requestdownloadfile9).
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | [BaseContext](js-apis-inner-application-baseContext.md) | Yes| Application-based context.|
| config | [DownloadConfig](#downloadconfig) | Yes| Download configurations.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[DownloadTask](#downloadtask)&gt; | Promise used to return the result.|
**Example**
```js
let downloadTask;
request.download(globalThis.abilityContext, { url: 'https://xxxx/xxxx.hap' }).then((data) => {
downloadTask = data;
}).catch((err) => {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
})
```
## request.download<sup>(deprecated)</sup>
download(context: BaseContext, config: DownloadConfig, callback: AsyncCallback&lt;DownloadTask&gt;): void;
Downloads files. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [request.downloadFile<sup>9+</sup>](#requestdownloadfile9-1).
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.MiscServices.Download
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| context | [BaseContext](js-apis-inner-application-baseContext.md) | Yes| Application-based context.|
| config | [DownloadConfig](#downloadconfig) | Yes| Download configurations.|
| callback | AsyncCallback&lt;[DownloadTask](#downloadtask)&gt; | Yes| Callback used to return the result.|
**Example**
```js
let downloadTask;
request.download(globalThis.abilityContext, { url: 'https://xxxx/xxxxx.hap',
filePath: 'xxx/xxxxx.hap'}, (err, data) => {
if (err) {
console.error('Failed to request the download. Cause: ' + JSON.stringify(err));
return;
}
downloadTask = data;
});
```
## DownloadTask ## DownloadTask
Implements file downloads. Before using any APIs of this class, you must obtain a **DownloadTask** object through [request.downloadFile<sup>9+</sup>](#requestdownloadfile9) in promise mode or [request.downloadFile<sup>9+</sup>](#requestdownloadfile9-1) in callback mode. Implements file downloads. Before using any APIs of this class, you must obtain a **DownloadTask** object through [request.downloadFile<sup>9+</sup>](#requestdownloadfile9) in promise mode or [request.downloadFile<sup>9+</sup>](#requestdownloadfile9-1) in callback mode.
...@@ -1050,7 +885,7 @@ Subscribes to a download event. This API uses an asynchronous callback to return ...@@ -1050,7 +885,7 @@ Subscribes to a download event. This API uses an asynchronous callback to return
| type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (download progress).| | type | string | Yes| Type of the event to subscribe to. The value is **'progress'** (download progress).|
| callback | function | Yes| Callback for the download progress event.| | callback | function | Yes| Callback for the download progress event.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -1084,7 +919,7 @@ Unsubscribes from a download event. This API uses an asynchronous callback to re ...@@ -1084,7 +919,7 @@ Unsubscribes from a download event. This API uses an asynchronous callback to re
| type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (download progress).| | type | string | Yes| Type of the event to unsubscribe from. The value is **'progress'** (download progress).|
| callback | function | No| Callback for the download progress event.| | callback | function | No| Callback for the download progress event.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -1172,7 +1007,7 @@ Subscribes to the download task failure event. This API uses an asynchronous cal ...@@ -1172,7 +1007,7 @@ Subscribes to the download task failure event. This API uses an asynchronous cal
| type | string | Yes| Type of the event to subscribe to. The value is **'fail'** (download failure).| | type | string | Yes| Type of the event to subscribe to. The value is **'fail'** (download failure).|
| callback | function | Yes| Callback for the download task failure event.| | callback | function | Yes| Callback for the download task failure event.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -1205,7 +1040,7 @@ Unsubscribes from the download task failure event. This API uses an asynchronous ...@@ -1205,7 +1040,7 @@ Unsubscribes from the download task failure event. This API uses an asynchronous
| type | string | Yes| Type of the event to unsubscribe from. The value is **'fail'** (download failure).| | type | string | Yes| Type of the event to unsubscribe from. The value is **'fail'** (download failure).|
| callback | function | No| Callback for the download task failure event.| | callback | function | No| Callback for the download task failure event.|
Parameters of the callback function Parameters of the callback function
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
...@@ -1265,7 +1100,7 @@ Deletes this download task. This API uses an asynchronous callback to return the ...@@ -1265,7 +1100,7 @@ Deletes this download task. This API uses an asynchronous callback to return the
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the task deletion result. | | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the task deletion result.|
**Example** **Example**
......
...@@ -47,7 +47,7 @@ Provides data items for setting the display effects. ...@@ -47,7 +47,7 @@ Provides data items for setting the display effects.
| ANIMATOR_DURATION_SCALE | string | Yes | Yes | Scale factor for the animation duration. This affects the start delay and duration of all such animations.<br>If the value is **0**, the animation ends immediately. The default value is **1**.| | ANIMATOR_DURATION_SCALE | string | Yes | Yes | Scale factor for the animation duration. This affects the start delay and duration of all such animations.<br>If the value is **0**, the animation ends immediately. The default value is **1**.|
| TRANSITION_ANIMATION_SCALE | string | Yes | Yes | Scale factor for transition animations.<br>The value **0** indicates that the transition animations are disabled. | | TRANSITION_ANIMATION_SCALE | string | Yes | Yes | Scale factor for transition animations.<br>The value **0** indicates that the transition animations are disabled. |
| WINDOW_ANIMATION_SCALE | string | Yes | Yes | Scale factor for normal window animations.<br>The value **0** indicates that window animations are disabled. | | WINDOW_ANIMATION_SCALE | string | Yes | Yes | Scale factor for normal window animations.<br>The value **0** indicates that window animations are disabled. |
| DISPLAY_INVERSION_STATUS | string | Yes | Yes | Whether display color inversion is enabled.<br>**1**: Display color inversion is enabled.<br>**0**: Display color inversion is disabled. | | DISPLAY_INVERSION_STATUS | string | Yes | Yes | Whether display color inversion is enabled.<br>**1**: Display color inversion is enabled.<br>**0**: Display color inversion is disabled.|
## general ## general
...@@ -185,121 +185,6 @@ Provides data items for setting wireless network information. ...@@ -185,121 +185,6 @@ Provides data items for setting wireless network information.
| WIFI_STATUS | string | Yes | Yes | Whether Wi-Fi is available.<br>**true**: Wi-Fi is available.<br>**false**: Wi-Fi is unavailable.| | WIFI_STATUS | string | Yes | Yes | Whether Wi-Fi is available.<br>**true**: Wi-Fi is available.<br>**false**: Wi-Fi is unavailable.|
| WIFI_WATCHDOG_STATUS | string | Yes | Yes | Whether Wi-Fi watchdog is available.<br>**true**: Wi-Fi watchdog is available.<br>**false**: Wi-Fi watchdog is unavailable.| | WIFI_WATCHDOG_STATUS | string | Yes | Yes | Whether Wi-Fi watchdog is available.<br>**true**: Wi-Fi watchdog is available.<br>**false**: Wi-Fi watchdog is unavailable.|
## setting.getURI
getURI(name: string, callback: AsyncCallback\<object>): void
Obtains the URI of a data item. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Applications.settings.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items|
| callback | AsyncCallback\<object> | Yes | Callback used to obtain the URI of the data item. |
**Example**
```js
settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS, (uri) => {
console.log(`callback:uri -> ${JSON.stringify(uri)}`)
})
```
## setting.getURI
getURI(name: string): Promise\<object>
Obtains the URI of a data item. This API uses a promise to return the result.
**System capability**: SystemCapability.Applications.settings.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items|
**Return value**
| Type | Description |
| ---------------- | ------------------------------------ |
| Promise\<object> | Promise used to return the URI of the data item.|
**Example**
```js
settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS).then((uri) => {
console.log(`promise:uri -> ${JSON.stringify(uri)}`)
})
```
## setting.getValue
getValue(dataAbilityHelper: DataAbilityHelper, name: string, callback: AsyncCallback\<object>): void
Obtains the value of a data item in the database. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Applications.settings.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
| dataAbilityHelper | [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br> - Existing data items in the database<br>- Custom data items|
| callback | AsyncCallback\<object> | Yes | Callback used to return the value of the data item. |
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
let helper = featureAbility.acquireDataAbilityHelper(uri);
settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, (err, value) => {
if (err) {
console.error(`Failed to get the setting. ${err.message} `);
return;
}
console.log(`callback:value -> ${JSON.stringify(value)}`)
});
```
## setting.getValue
getValue(dataAbilityHelper: DataAbilityHelper, name: string): Promise\<object>
Obtains the value of a data item in the database. This API uses a promise to return the result.
**System capability**: SystemCapability.Applications.settings.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
| dataAbilityHelper | [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br> - Existing data items in the database<br>- Custom data items|
**Return value**
| Type | Description |
| ---------------- | ----------------------------------- |
| Promise\<object> | Promise used to return the value of the data item.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
let helper = featureAbility.acquireDataAbilityHelper(uri);
settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS).then((value) => {
console.log(`promise:value -> ${JSON.stringify(value)}`)
});
```
## settings.setValue ## settings.setValue
...@@ -325,9 +210,11 @@ Sets the value for a data item. This API uses an asynchronous callback to return ...@@ -325,9 +210,11 @@ Sets the value for a data item. This API uses an asynchronous callback to return
```js ```js
import featureAbility from '@ohos.ability.featureAbility'; import featureAbility from '@ohos.ability.featureAbility';
// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValue API will update the value of the data item.) // Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValue API will update its value.)
let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
let helper = featureAbility.acquireDataAbilityHelper(uri); let helper = featureAbility.acquireDataAbilityHelper(uri);
// @ts-ignore
// The value of the data item is a string.
settings.setValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100', (status) => { settings.setValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100', (status) => {
console.log('Callback return whether value is set.'); console.log('Callback return whether value is set.');
}); });
...@@ -365,6 +252,8 @@ import featureAbility from '@ohos.ability.featureAbility'; ...@@ -365,6 +252,8 @@ import featureAbility from '@ohos.ability.featureAbility';
// Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValue API will update the value of the data item.) // Update the value of SCREEN_BRIGHTNESS_STATUS. (As this data item exists in the database, the setValue API will update the value of the data item.)
let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
let helper = featureAbility.acquireDataAbilityHelper(uri); let helper = featureAbility.acquireDataAbilityHelper(uri);
// @ts-ignore
// The value of the data item is a string.
settings.setValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100').then((status) => { settings.setValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '100').then((status) => {
console.log('Callback return whether value is set.'); console.log('Callback return whether value is set.');
}); });
...@@ -500,12 +389,154 @@ Obtains the URI of a data item. ...@@ -500,12 +389,154 @@ Obtains the URI of a data item.
let urivar = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS); let urivar = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
``` ```
## settings.getValueSync<sup>8+</sup> ## setting.getURI<sup>(deprecated)</sup>
getURI(name: string, callback: AsyncCallback\<object>): void
Obtains the URI of a data item. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
**System capability**: SystemCapability.Applications.settings.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ---------------------- | ---- | ------------------------------------------------------------ |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items|
| callback | AsyncCallback\<object> | Yes | Callback used to obtain the URI of the data item. |
**Example**
```js
settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS, (uri) => {
console.log(`callback:uri -> ${JSON.stringify(uri)}`)
})
```
## setting.getURI<sup>(deprecated)</sup>
getURI(name: string): Promise\<object>
Obtains the URI of a data item. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
**System capability**: SystemCapability.Applications.settings.Core
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------------------------------------ |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items|
**Return value**
| Type | Description |
| ---------------- | ------------------------------------ |
| Promise\<object> | Promise used to return the URI of the data item.|
**Example**
```js
settings.getURI(settings.display.SCREEN_BRIGHTNESS_STATUS).then((uri) => {
console.log(`promise:uri -> ${JSON.stringify(uri)}`)
})
```
## setting.getValue<sup>(deprecated)</sup>
getValue(dataAbilityHelper: DataAbilityHelper, name: string, callback: AsyncCallback\<object>): void
Obtains the value of a data item in the database. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Applications.settings.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
| dataAbilityHelper | [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br> - Existing data items in the database<br>- Custom data items|
| callback | AsyncCallback\<object> | Yes | Callback used to return the value of the data item. |
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
let helper = featureAbility.acquireDataAbilityHelper(uri);
settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, (err, value) => {
if (err) {
console.error(`Failed to get the setting. ${err.message} `);
return;
}
console.log(`callback:value -> ${JSON.stringify(value)}`)
});
```
## setting.getValue<sup>(deprecated)</sup>
getValue(dataAbilityHelper: DataAbilityHelper, name: string): Promise\<object>
Obtains the value of a data item in the database. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9.
**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Applications.settings.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ----------------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
| dataAbilityHelper | [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br> - Existing data items in the database<br>- Custom data items|
**Return value**
| Type | Description |
| ---------------- | ----------------------------------- |
| Promise\<object> | Promise used to return the value of the data item.|
**Example**
```js
import featureAbility from '@ohos.ability.featureAbility';
let uri = settings.getUriSync(settings.display.SCREEN_BRIGHTNESS_STATUS);
let helper = featureAbility.acquireDataAbilityHelper(uri);
settings.getValue(helper, settings.display.SCREEN_BRIGHTNESS_STATUS).then((value) => {
console.log(`promise:value -> ${JSON.stringify(value)}`)
});
```
## settings.getValueSync<sup>(deprecated)</sup>
getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string getValueSync(dataAbilityHelper: DataAbilityHelper, name: string, defValue: string): string
Obtains the value of a data item. Unlike **getValue**, this API returns the result synchronously. Obtains the value of a data item. Unlike **getValue**, this API returns the result synchronously.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9.
**Model restriction**: This API can be used only in the FA model.
**System capability**: SystemCapability.Applications.settings.Core **System capability**: SystemCapability.Applications.settings.Core
**Parameters** **Parameters**
...@@ -514,7 +545,7 @@ Obtains the value of a data item. Unlike **getValue**, this API returns the resu ...@@ -514,7 +545,7 @@ Obtains the value of a data item. Unlike **getValue**, this API returns the resu
| ----------------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ | | ----------------- | ------------------------------------------------- | ---- | ------------------------------------------------------------ |
| dataAbilityHelper | [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. | | dataAbilityHelper | [DataAbilityHelper](js-apis-inner-ability-dataAbilityHelper.md) | Yes | **DataAbilityHelper** class. |
| name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items| | name | string | Yes | Name of the target data item. Data items can be classified as follows:<br>- Existing data items in the database<br>- Custom data items|
| defValue | string | Yes | Default value, which is returned when the value of a data item is not found in the database. Set this parameter as needed. | | defValue | string | Yes | Default value, which is returned when the value of a data item is not found in the database. Set this parameter as needed.|
**Return value** **Return value**
...@@ -533,7 +564,7 @@ let helper = featureAbility.acquireDataAbilityHelper(uri); ...@@ -533,7 +564,7 @@ let helper = featureAbility.acquireDataAbilityHelper(uri);
let value = settings.getValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '10'); let value = settings.getValueSync(helper, settings.display.SCREEN_BRIGHTNESS_STATUS, '10');
``` ```
## settings.setValueSync<sup>8+</sup> ## settings.setValueSync<sup>(deprecated)</sup>
setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean setValueSync(dataAbilityHelper: DataAbilityHelper, name: string, value: string): boolean
...@@ -541,6 +572,12 @@ Sets the value for a data item. Unlike **setValue**, this API returns the result ...@@ -541,6 +572,12 @@ Sets the value for a data item. Unlike **setValue**, this API returns the result
If the specified data item exists in the database, the **setValueSync** method updates the value of the data item. If the data item does not exist in the database, the **setValueSync** method inserts the data item into the database. If the specified data item exists in the database, the **setValueSync** method updates the value of the data item. If the data item does not exist in the database, the **setValueSync** method inserts the data item into the database.
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9.
**Model restriction**: This API can be used only in the FA model.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS (available only to system applications) **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS (available only to system applications)
**System capability**: SystemCapability.Applications.settings.Core **System capability**: SystemCapability.Applications.settings.Core
......
...@@ -21,8 +21,6 @@ fetch(Object): void ...@@ -21,8 +21,6 @@ fetch(Object): void
Obtains data through a network. Obtains data through a network.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
**Parameters** **Parameters**
...@@ -33,8 +31,8 @@ Obtains data through a network. ...@@ -33,8 +31,8 @@ Obtains data through a network.
| header | Object | No| Request header.| | header | Object | No| Request header.|
| method | string | No| Request method. The default value is **GET**. The value can be **OPTIONS**, **GET**, **HEAD**, **POST**, **PUT**, **DELETE **or **TRACE**.| | method | string | No| Request method. The default value is **GET**. The value can be **OPTIONS**, **GET**, **HEAD**, **POST**, **PUT**, **DELETE **or **TRACE**.|
| responseType | string | No| Response type. The return type can be text or JSON. By default, the return type is determined based on **Content-Type** in the header returned by the server. For details, see return values in the **success** callback.| | responseType | string | No| Response type. The return type can be text or JSON. By default, the return type is determined based on **Content-Type** in the header returned by the server. For details, see return values in the **success** callback.|
| success | Function | No| Called when the data is obtained successfully.| | success | Function | No| Called when data is obtained successfully. The return value is [FetchResponse](#fetchresponse). |
| fail | Function | No| Called when the data failed to be obtained.| | fail | Function | No| Called when data failed to be obtained.|
| complete | Function | No| Called when the execution is complete.| | complete | Function | No| Called when the execution is complete.|
**Table 1** Mapping between data and Content-Type **Table 1** Mapping between data and Content-Type
...@@ -46,7 +44,7 @@ Obtains data through a network. ...@@ -46,7 +44,7 @@ Obtains data through a network.
| Object | Not set| The default value of **Content-Type** is **application/x-www-form-urlencoded**. The **data** value is encoded based on the URL rule and appended in the request body.| | Object | Not set| The default value of **Content-Type** is **application/x-www-form-urlencoded**. The **data** value is encoded based on the URL rule and appended in the request body.|
| Object | application/x-www-form-urlencoded | The value of data is encoded based on the URL rule and is used as the request body.| | Object | application/x-www-form-urlencoded | The value of data is encoded based on the URL rule and is used as the request body.|
Return values in the **success** callback ## FetchResponse
| Name| Type| Description| | Name| Type| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
......
...@@ -33,22 +33,15 @@ Obtains the network type. ...@@ -33,22 +33,15 @@ Obtains the network type.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. | | success | Function | No | Called when the execution is successful. The return value is [NetworkResponse](#networkresponse). |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No | Called when the operation fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete | | complete | Function | No | Called when the execution is complete |
The following value will be returned when the multimedia volume is obtained. Return value of the **fail** callback:
| Parameter | Type | Description | | Error Code | Description |
| -------- | -------- | -------- |
| metered | boolean | Whether&nbsp;the&nbsp;billing&nbsp;is&nbsp;based&nbsp;on&nbsp;the&nbsp;data&nbsp;volume. |
| type | string | Network&nbsp;type.&nbsp;The&nbsp;value&nbsp;can&nbsp;be&nbsp;**2G**,&nbsp;**3G**,&nbsp;**4G**,&nbsp;**5G**,&nbsp;**WiFi**,&nbsp;or&nbsp;**none**. |
One of the following error codes will be returned if the operation fails.
| Error&nbsp;Code | Description |
| -------- | -------- | | -------- | -------- |
| 602 | The&nbsp;current&nbsp;permission&nbsp;is&nbsp;not&nbsp;declared. | | 602 | The current permission is not declared. |
**Example** **Example**
...@@ -80,22 +73,15 @@ Listens to the network connection state. If this method is called multiple times ...@@ -80,22 +73,15 @@ Listens to the network connection state. If this method is called multiple times
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;network&nbsp;connection&nbsp;state&nbsp;changes | | success | Function | No | Called when the network connection state changes |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;multimedia&nbsp;volume&nbsp;fails&nbsp;to&nbsp;be&nbsp;obtained. | | fail | Function | No | Called when the multimedia volume fails to be obtained. |
The following value will be returned when the multimedia volume is obtained.
| Parameter | Type | Description |
| -------- | -------- | -------- |
| metered | boolean | Whether&nbsp;the&nbsp;billing&nbsp;is&nbsp;based&nbsp;on&nbsp;the&nbsp;data&nbsp;volume. |
| type | string | Network&nbsp;type.&nbsp;The&nbsp;value&nbsp;can&nbsp;be&nbsp;**2G**,&nbsp;**3G**,&nbsp;**4G**,&nbsp;**5G**,&nbsp;**WiFi**,&nbsp;or&nbsp;**none**. |
One of the following error codes will be returned if the listening fails. Return value of the **fail** callback:
| Error&nbsp;Code | Description | | Error Code | Description |
| -------- | -------- | | -------- | -------- |
| 602 | The&nbsp;current&nbsp;permission&nbsp;is&nbsp;not&nbsp;declared. | | 602 | The current permission is not declared. |
| 200 | The&nbsp;subscription&nbsp;fails. | | 200 | The subscription fails. |
**Example** **Example**
...@@ -132,3 +118,10 @@ export default { ...@@ -132,3 +118,10 @@ export default {
}, },
} }
``` ```
## NetworkResponse
| Parameter | Type | Description |
| -------- | -------- | -------- |
| metered | boolean | Whether the billing is based on the data volume. |
| type | string | Network type. The value can be **2G**, **3G**, **4G**, **5G**, **WiFi**, or **none**. |
\ No newline at end of file
...@@ -51,7 +51,7 @@ export default { ...@@ -51,7 +51,7 @@ export default {
## storage.set ## storage.set
get(options: SetStorageOptions): void set(options: SetStorageOptions): void
Sets the value in the cache based on the specified key. Sets the value in the cache based on the specified key.
...@@ -167,8 +167,8 @@ export default { ...@@ -167,8 +167,8 @@ export default {
| key | string | Yes | Key of the data to set. | | key | string | Yes | Key of the data to set. |
| value | string | Yes | New value to set. The length must be less than 128 bytes. | | value | string | Yes | New value to set. The length must be less than 128 bytes. |
| success | () => void | No | Called when **storage.set()** is called successfully. | | success | () => void | No | Called when **storage.set()** is called successfully. |
| fail | (data: string, code: number) => void | No | Called to return the result when **storage.get()** fails to be called. **data** is the error information, and **code** indicates the error code. | | fail | (data: string, code: number) => void | No | Called to return the result when **storage.set()** fails to be called. **data** is the error information, and **code** indicates the error code. |
| complete | () => void | No | Called when **storage.get()** is complete. | | complete | () => void | No | Called when **storage.set()** is complete. |
## ClearStorageOptions ## ClearStorageOptions
......
...@@ -5,6 +5,7 @@ The **usb** module provides USB device management functions, including USB devic ...@@ -5,6 +5,7 @@ The **usb** module provides USB device management functions, including USB devic
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> This module is deprecated since API version 9. You are advised to use [`@ohos.usbManager`](js-apis-usbManager.md) instead.
## Modules to Import ## Modules to Import
......
此差异已折叠。
...@@ -51,7 +51,7 @@ This component can contain only one child component. ...@@ -51,7 +51,7 @@ This component can contain only one child component.
| Normal | Normal button (without rounded corners by default). | | Normal | Normal button (without rounded corners by default). |
> **NOTE** > **NOTE**
> - The rounded corner of a button is set by using [borderRadius](ts-universal-attributes-border.md), rather than by using the **border** API. > - The rounded corner of a button is set by using [borderRadius](ts-universal-attributes-border.md), rather than by using the **border** API. Only a button-wide rounded corner setting is supported.
> - For a button of the **Capsule** type, the **borderRadius** settings do not take effect, and its rounded corner is always half of the button height. > - For a button of the **Capsule** type, the **borderRadius** settings do not take effect, and its rounded corner is always half of the button height.
> - For a button of the **Circle** type, its radius is the value of **borderRadius** (if set) or the width or height (whichever is smaller). > - For a button of the **Circle** type, its radius is the value of **borderRadius** (if set) or the width or height (whichever is smaller).
> - The button text is set using the [text style attributes](ts-universal-attributes-text-style.md). > - The button text is set using the [text style attributes](ts-universal-attributes-text-style.md).
......
...@@ -37,7 +37,7 @@ In addition to the [universal attributes](ts-universal-attributes-size.md), the ...@@ -37,7 +37,7 @@ In addition to the [universal attributes](ts-universal-attributes-size.md), the
| viewPort | {<br>x?: number \| string,<br>y?: number \| string,<br>width?: number \| string,<br>height?: number \| string<br>} | { x:0, y:0, width:0, height:0 } | View port of the shape.| | viewPort | {<br>x?: number \| string,<br>y?: number \| string,<br>width?: number \| string,<br>height?: number \| string<br>} | { x:0, y:0, width:0, height:0 } | View port of the shape.|
| fill | [ResourceColor](ts-types.md) | Color.Black | Color of the fill area.| | fill | [ResourceColor](ts-types.md) | Color.Black | Color of the fill area.|
| fillOpacity | number \| string \| [Resource](ts-types.md#resource)| 1 | Opacity of the fill area.| | fillOpacity | number \| string \| [Resource](ts-types.md#resource)| 1 | Opacity of the fill area.|
| stroke | [ResourceColor](ts-types.md) | - | Stroke color. If this attribute is not set, no stroke is displayed.| | stroke | [ResourceColor](ts-types.md) | - | Stroke color. If this attribute is not set, the component does not have any stroke.|
| strokeDashArray | Array&lt;Length&gt; | [] | Stroke dashes.| | strokeDashArray | Array&lt;Length&gt; | [] | Stroke dashes.|
| strokeDashOffset | number \| string | 0 | Offset of the start point for drawing the stroke.| | strokeDashOffset | number \| string | 0 | Offset of the start point for drawing the stroke.|
| strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | Cap style of the stroke.| | strokeLineCap | [LineCapStyle](ts-appendix-enums.md#linecapstyle) | LineCapStyle.Butt | Cap style of the stroke.|
...@@ -145,91 +145,3 @@ struct ShapeExample { ...@@ -145,91 +145,3 @@ struct ShapeExample {
``` ```
![en-us_image_0000001184628104](figures/en-us_image_0000001184628104.png) ![en-us_image_0000001184628104](figures/en-us_image_0000001184628104.png)
### Example 2
```ts
// xxx.ets
@Entry
@Component
struct ShapeMeshExample {
@State columnVal: number = 0
@State rowVal: number = 0
@State count: number = 0
@State verts: Array<number> = []
@State shapeWidth: number = 600
@State shapeHeight: number = 600
build() {
Column() {
Shape() {
Rect()
.width('250px')
.height('250px')
.radiusWidth('10px')
.radiusHeight('10px')
.stroke('10px')
.margin({ left: '10px', top: '10px' })
.strokeWidth('10px')
.fill(Color.Blue)
Rect()
.width('250px')
.height('250px')
.radiusWidth('10px')
.radiusHeight('10px')
.stroke('10px')
.margin({ left: '270px', top: '10px' })
.strokeWidth('10px')
.fill(Color.Red)
}
.mesh(this.verts, this.columnVal, this.rowVal)
.width(this.shapeWidth + 'px')
.height(this.shapeHeight + 'px')
// The mesh distortion effect is displayed when the component is touched.
.onTouch((event: TouchEvent) => {
var touchX = event.touches[0].x * 2
var touchY = event.touches[0].y * 2
this.columnVal = 20
this.rowVal = 20
this.count = (this.columnVal + 1) * (this.rowVal + 1)
var orig = [this.count * 2]
var index = 0
for (var i = 0; i <= this.rowVal; i++) {
var fy = this.shapeWidth * i / this.rowVal
for (var j = 0; j <= this.columnVal; j++) {
var fx = this.shapeWidth * j / this.columnVal
orig[index * 2 + 0] = this.verts[index * 2 + 0] = fx
orig[index * 2 + 1] = this.verts[index * 2 + 1] = fy
index++;
}
}
for (var k = 0; k < this.count * 2; k += 2) {
var dx = touchX - orig[k + 0]
var dy = touchY - orig[k + 1]
var dd = dx * dx + dy * dy
var d = Math.sqrt(dd)
var pull = 80000 / (dd * d)
if (pull >= 1) {
this.verts[k + 0] = touchX
this.verts[k + 1] = touchY
} else {
this.verts[k + 0] = orig[k + 0] + dx * pull
this.verts[k + 1] = orig[k + 1] + dy * pull
}
}
})
}
.width('600px')
.height('600px')
.border({ width: 3, color: Color.Black })
}
}
```
Below is how the component is displayed when not being touched.
![en-us_image1_0000001184628104](figures/en-us_image1_0000001184628104.png)
The mesh distortion effect is displayed when the component is touched, as shown below.
![en-us_image2_0000001184628104](figures/en-us_image2_0000001184628104.png)
...@@ -39,7 +39,7 @@ This API is used only for test purposes. ...@@ -39,7 +39,7 @@ This API is used only for test purposes.
### getInspectorTree<sup>9+</sup> ### getInspectorTree<sup>9+</sup>
getInspectorTree(): string getInspectorTree(): Object
Obtains the component tree and component attributes. Obtains the component tree and component attributes.
...@@ -49,7 +49,7 @@ This API is used only for test purposes. ...@@ -49,7 +49,7 @@ This API is used only for test purposes.
| Type | Description | | Type | Description |
| ------ | --------------------------- | | ------ | --------------------------- |
| string | JSON string of the component tree and component attribute list.| | Object | JSON object of the component tree and component attribute list.|
### sendEventByKey<sup>9+</sup> ### sendEventByKey<sup>9+</sup>
...@@ -181,7 +181,7 @@ struct IdExample { ...@@ -181,7 +181,7 @@ struct IdExample {
}.margin({ top: 20 }) }.margin({ top: 20 })
.onClick(() => { .onClick(() => {
console.info(getInspectorByKey("click")) console.info(getInspectorByKey("click"))
console.info(getInspectorTree()) console.info(JSON.stringify(getInspectorTree()))
this.text = "Button 'click to start' is clicked" this.text = "Button 'click to start' is clicked"
setTimeout(() => { setTimeout(() => {
sendEventByKey("longClick", 11, "") // Send a long-click event to the component whose ID is "longClick". sendEventByKey("longClick", 11, "") // Send a long-click event to the component whose ID is "longClick".
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册