提交 b0cc07a7 编写于 作者: E ester.zhou 提交者: Gitee

Merge branch 'OpenHarmony-3.2-Beta3' of gitee.com:openharmony/docs into C3-0927

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
...@@ -151,9 +151,9 @@ zh-cn/application-dev/work-scheduler/ @HelloCrease ...@@ -151,9 +151,9 @@ zh-cn/application-dev/work-scheduler/ @HelloCrease
zh-cn/application-dev/internationalization/ @HelloCrease zh-cn/application-dev/internationalization/ @HelloCrease
zh-cn/application-dev/device/usb-overview.md @ge-yafang zh-cn/application-dev/device/usb-overview.md @ge-yafang
zh-cn/application-dev/device/usb-guidelines.md @ge-yafang zh-cn/application-dev/device/usb-guidelines.md @ge-yafang
zh-cn/application-dev/device/device-location-overview.md @sun-yue14 zh-cn/application-dev/device/device-location-overview.md @zengyawen
zh-cn/application-dev/device/device-location-info.md @sun-yue14 zh-cn/application-dev/device/device-location-info.md @zengyawen
zh-cn/application-dev/device/device-location-geocoding.md @sun-yue14 zh-cn/application-dev/device/device-location-geocoding.md @zengyawen
zh-cn/application-dev/device/sensor-overview.md @HelloCrease zh-cn/application-dev/device/sensor-overview.md @HelloCrease
zh-cn/application-dev/device/sensor-guidelines.md @HelloCrease zh-cn/application-dev/device/sensor-guidelines.md @HelloCrease
zh-cn/application-dev/device/vibrator-overview.md @HelloCrease zh-cn/application-dev/device/vibrator-overview.md @HelloCrease
...@@ -231,7 +231,7 @@ zh-cn/application-dev/reference/apis/js-apis-audio.md @zengyawen ...@@ -231,7 +231,7 @@ zh-cn/application-dev/reference/apis/js-apis-audio.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-camera.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-camera.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-image.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-image.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-media.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-media.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-medialibrary.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-medialibrary.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-i18n.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-i18n.md @HelloCrease
zh-cn/application-dev/reference/apis/js-apis-intl.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-intl.md @HelloCrease
zh-cn/application-dev/reference/apis/js-apis-resource-manager.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-resource-manager.md @HelloCrease
...@@ -277,14 +277,14 @@ zh-cn/application-dev/reference/apis/js-apis-http.md @zengyawen ...@@ -277,14 +277,14 @@ zh-cn/application-dev/reference/apis/js-apis-http.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-request.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-request.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-socket.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-socket.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-webSocket.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-webSocket.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-bluetooth.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-bluetooth.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-nfcTag.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-nfcTag.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-nfcTech.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-nfcTech.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-tagSession.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-tagSession.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-connectedTag.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-connectedTag.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-rpc.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-rpc.md @qinxiaowang
zh-cn/application-dev/reference/apis/js-apis-wifi.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-wifi.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-wifiext.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-wifiext.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-accessibility.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-accessibility.md @qinxiaowang
zh-cn/application-dev/reference/apis/js-apis-faultLogger.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-faultLogger.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-hiappevent.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-hiappevent.md @zengyawen
...@@ -293,18 +293,18 @@ zh-cn/application-dev/reference/apis/js-apis-hidebug.md @zengyawen ...@@ -293,18 +293,18 @@ zh-cn/application-dev/reference/apis/js-apis-hidebug.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-hilog.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-hilog.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-hitracechain.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-hitracechain.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-hitracemeter.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-hitracemeter.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-inputmethod.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-inputmethodengine.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-pasteboard.md @ge-yafang zh-cn/application-dev/reference/apis/js-apis-pasteboard.md @ge-yafang
zh-cn/application-dev/reference/apis/js-apis-screen-lock.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-screen-lock.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-system-time.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-system-time.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-wallpaper.md @bmeangel zh-cn/application-dev/reference/apis/js-apis-wallpaper.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-timer.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-timer.md @HelloCrease
zh-cn/application-dev/reference/apis/js-apis-battery-info.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-battery-info.md @qinxiaowang
zh-cn/application-dev/reference/apis/js-apis-brightness.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-brightness.md @qinxiaowang
zh-cn/application-dev/reference/apis/js-apis-device-info.md @qinxiaowang zh-cn/application-dev/reference/apis/js-apis-device-info.md @qinxiaowang
zh-cn/application-dev/reference/apis/js-apis-device-manager.md zh-cn/application-dev/reference/apis/js-apis-device-manager.md
zh-cn/application-dev/reference/apis/js-apis-geolocation.md @sun-yue14 zh-cn/application-dev/reference/apis/js-apis-geolocation.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-inputconsumer.md @HelloCrease
zh-cn/application-dev/reference/apis/js-apis-inputdevice.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-inputdevice.md @HelloCrease
zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md @HelloCrease zh-cn/application-dev/reference/apis/js-apis-inputeventclient.md @HelloCrease
...@@ -366,3 +366,6 @@ zh-cn/application-dev/reference/js-service-widget-ui @HelloCrease ...@@ -366,3 +366,6 @@ zh-cn/application-dev/reference/js-service-widget-ui @HelloCrease
zh-cn/application-dev/website.md @zengyawen zh-cn/application-dev/website.md @zengyawen
zh-cn/application-dev/faqs/ @zengyawen zh-cn/application-dev/faqs/ @zengyawen
zh-cn/application-dev/reference/apis/js-apis-useriam-faceauth.md @zengyawen zh-cn/application-dev/reference/apis/js-apis-useriam-faceauth.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-userfilemanager.md @zengyawen
zh-cn/application-dev/reference/apis/js-apis-cryptoFramework.md @zengyawen
zh-cn/application-dev/reference/apis/Readme-CN.md @zengyawen
\ No newline at end of file
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
<!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/--> <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/--> <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
<!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/--> <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
<filteritem type="filename" name="*.jpg|*.png|*.gif|*.pdf|*.xlsm" desc="already checked"/> <filteritem type="filename" name="*.jpg|*.png|*.gif|*.pdf|*.xlsm|*.zip" desc="already checked"/>
</filefilter> </filefilter>
</filefilterlist> </filefilterlist>
......
...@@ -14,23 +14,23 @@ The data provider can directly use the **DataShare** framework to share data wit ...@@ -14,23 +14,23 @@ The data provider can directly use the **DataShare** framework to share data wit
Before you get started, familiarize yourself with the following concepts: Before you get started, familiarize yourself with the following concepts:
- Data provider - **Data provider**
An application that provides data and implements related services. It is also called a producer or server. An application that provides data and implements related services. It is also called a producer or server.
- Data consumer - **Data consumer**
An application that accesses the data or services provided by a data provider. It is also called a client. An application that accesses the data or services provided by a data provider. It is also called a client.
- Value bucket (**ValuesBucket**) - **ValuesBucket**
One or more data records stored in the form of key-value (KV) pairs. The keys are of the string type. The values can be of the number, string, Boolean, or Unit8Array type. One or more data records stored in the form of key-value (KV) pairs. The keys are of the string type. The values can be of the number, string, Boolean, or Unit8Array type.
- Result set - **Result set**
A collection of query results. Flexible data access modes are provided for users to obtain data. A collection of query results. Flexible data access modes are provided for users to obtain data.
- Predicate - **Predicate**
Conditions specified for updating, deleting, or querying data in the database. Conditions specified for updating, deleting, or querying data in the database.
......
...@@ -6,100 +6,98 @@ Applications save data to distributed databases by calling the DDS APIs. The DDS ...@@ -6,100 +6,98 @@ Applications save data to distributed databases by calling the DDS APIs. The DDS
You do not need to care about the implementation of the database locking mechanism. You do not need to care about the implementation of the database locking mechanism.
## Basic Concepts ## Basic Concepts
- **KV data model** ### KV Data Model
The key-value \(KV\) data model allows data to be organized, indexed, and stored in key-value pairs. The key-value (KV) data model allows data to be organized, indexed, and stored in KV pairs.
The KV data model is suitable for storing service data that is not related. It provides better read and write performance than the SQL database. The KV data model is widely used in distributed scenarios because it handles database version compatibility issues and data synchronization conflicts easily. The distributed database is based on the KV data model and provides KV-based access interfaces. The KV data model is suitable for storing service data that is not related. It provides better read and write performance than the SQL database. The KV data model is widely used in distributed scenarios because it handles database version compatibility issues and data synchronization conflicts easily. The distributed database is based on the KV data model and provides KV-based access interfaces.
- **Distributed database transactions** ### Distributed Database Transaction
Distributed database transactions include local transactions \(same as the transactions of traditional databases\) and synchronization transactions. Synchronization transactions allow data to be synchronized between devices by local transaction. Synchronization of a local transaction modification either succeeds or fails on all the devices. Distributed database transactions include local transactions (same as the transactions of traditional databases) and synchronization transactions. Synchronization transactions allow data to be synchronized between devices by local transaction. Synchronization of a local transaction modification either succeeds or fails on all the devices.
- **Distributed database consistency** ### Distributed Database Consistency
In a distributed scenario, cross-device collaboration demands consistent data between the devices in the same network. The data consistency can be classified into the following types: In a distributed scenario, cross-device collaboration demands consistent data between the devices in the same network. The data consistency can be classified into the following types:
- **Strong consistency**: When data is inserted, deleted, or modified on a device, other devices in the same network will obtain the latest data immediately. - **Strong consistency**: When data is inserted, deleted, or modified on a device, other devices in the same network will obtain the latest data immediately.
- **Weak consistency**: When data is added, deleted, or modified on a device, other devices in the same network may or may not obtain the latest data. The data on these devices may be inconsistent after a certain period of time. - **Weak consistency**: When data is added, deleted, or modified on a device, other devices in the same network may or may not obtain the latest data. The data on these devices may be inconsistent after a certain period of time.
- **Eventual consistency**: When data is added, deleted, or modified on a device, other devices in the same network may not obtain the latest data immediately. However, data on these devices will become consistent after a certain period of time. - **Eventual consistency**: When data is added, deleted, or modified on a device, other devices in the same network may not obtain the latest data immediately. However, data on these devices will become consistent after a certain period of time.
Strong consistency has high requirements on distributed data management and may be used in distributed server deployment. The DDS supports only the eventual consistency because mobile devices are not always online and the network has no center. Strong consistency has high requirements on distributed data management and may be used in distributed server deployment. The DDS supports only the eventual consistency because mobile devices are not always online and the network has no center.
- **Distributed database synchronization** ### Distributed Database Synchronization
After discovering and authenticating a device, the underlying communication component notifies the upper-layer application \(including the DDS\) that the device goes online. The DDS then establishes an encrypted transmission channel to synchronize data between the two devices. After discovering and authenticating a device, the underlying communication component notifies the upper-layer application (including the DDS) that the device goes online. The DDS then establishes an encrypted transmission channel to synchronize data between the two devices.
The DDS provides the following synchronization modes: The DDS provides the following synchronization modes:
- **Manual synchronization**: Applications call **sync** to trigger a synchronization. The list of devices to be synchronized and the synchronization mode must be specified. The synchronization mode can be **PULL\_ONLY** \(pulling remote data to the local end\), **PUSH\_ONLY** \(pushing local data to the remote end\), or **PUSH\_PULL** \(pushing local data to the remote end and pulling remote data to the local end\). The internal interface supports condition-based synchronization. The data that meets the conditions can be synchronized to the remote end. - **Manual synchronization**: Applications call **sync()** to trigger a synchronization. The list of devices to be synchronized and the synchronization mode must be specified. The synchronization mode can be **PULL_ONLY** (pulling remote data to the local end), **PUSH_ONLY** (pushing local data to the remote end), or **PUSH_PULL** (pushing local data to the remote end and pulling remote data to the local end). The internal interface supports condition-based synchronization. The data that meets the conditions can be synchronized to the remote end.
- **Automatic synchronization**: includes full synchronization and condition-based subscription synchronization. In full synchronization, the distributed database automatically pushes local data to the remote end and pulls remote data to the local end when a device goes online or application data is updated. Applications do not need to call **sync**. The internal interface supports condition-based subscription synchronization. The data that meets the subscription conditions on the remote end is automatically synchronized to the local end. - **Automatic synchronization**: includes full synchronization and condition-based subscription synchronization. In full synchronization, the distributed database automatically pushes local data to the remote end and pulls remote data to the local end when a device goes online or application data is updated. Applications do not need to call **sync()**. The internal interface supports condition-based subscription synchronization. The data that meets the subscription conditions on the remote end is automatically synchronized to the local end.
- **Single KV store** ### Single KV Store
Data is saved locally in the unit of a single KV entry. Only one entry is saved for each key. Data can be modified only locally and synchronized to remote devices in sequence based on the update time. Data is saved locally in the unit of a single KV entry. Only one entry is saved for each key. Data can be modified only locally and synchronized to remote devices in sequence based on the update time.
- **Device KV store** ### Device KV Store
The device KV store is based on the single KV store. The local device ID is added to the key when KV data is stored in the device KV store. Data can be isolated, managed, and queried by device. However, the data synchronized from remote devices cannot be modified locally. The device KV store is based on the single KV store. The local device ID is added to the key when KV data is stored in the device KV store. Data can be isolated, managed, and queried by device. However, the data synchronized from remote devices cannot be modified locally.
- **Conflict resolution** ### Conflict Resolution
A data conflict occurs when multiple devices modify the same data and commit the modification to the database. The last write wins \(LWW\) is the default conflict resolution policy used for data conflicts. Based on the commit timestamps, the data with a later timestamp is used. Currently, customized conflict resolution policies are not supported. A data conflict occurs when multiple devices modify the same data and commit the modification to the database. The last write wins (LWW) is the default conflict resolution policy used for data conflicts. Based on the commit timestamps, the data with a later timestamp is used. Currently, customized conflict resolution policies are not supported.
- **Schema-based database management and data query based on predicates** ### Schema-based Database Management and Predicate-based Data Query
A schema is specified when you create or open a single KV store. Based on the schema, the database detects the value format of key-value pairs and checks the value structure. Based on the fields in the values, the database implements index creation and predicate-based query. A schema is specified when you create or open a single KV store. Based on the schema, the database detects the value format of KV pairs and checks the value structure. Based on the fields in the values, the database implements index creation and predicate-based query.
- **Distributed database backup** ### Distributed Database Backup
The DDS provides the database backup capability. You can set **backup** to **true** to enable daily backup. If a distributed database is damaged, the DDS deletes the database and restores the most recent data from the backup database. If no backup database is available, the DDS creates one. The DDS can also back up encrypted databases. The DDS provides the database backup capability. You can set **backup** to **true** to enable daily backup. If a distributed database is damaged, the DDS deletes the database and restores the most recent data from the backup database. If no backup database is available, the DDS creates one. The DDS can also back up encrypted databases.
## Working Principles ## Working Principles
The DDS supports distributed management of application database data in the OpenHarmony system. Data can be synchronized between multiple devices with the same account, delivering a consistent user experience across devices. The DDS consists of the following: The DDS supports distributed management of application database data in the OpenHarmony system. Data can be synchronized between multiple devices with the same account, delivering a consistent user experience across devices.
- **APIs**
The DDS provides APIs to create databases, access data, and subscribe to data. The APIs support the KV data model and common data types. They are highly compatible and easy to use, and can be released.
- **Service component**
The service component implements management of metadata, permissions, encryption, backup and restore, and multiple users, and completes initialization of the storage component, synchronization component, and communication adaptation layer of the distributed database. The DDS consists of the following:
- **Storage component** - **APIs**<br>The DDS provides APIs to create databases, access data, and subscribe to data. The APIs support the KV data model and common data types. They are highly compatible and easy to use, and can be released.
The storage component implements data access, data reduction, transactions, snapshots, database encryption, data combination, and conflict resolution. - **Service component**<br>The service component implements management of metadata, permissions, encryption, backup and restore, and multiple users, and completes initialization of the storage component, synchronization component, and communication adaptation layer of the distributed database.
- **Synchronization component** - **Storage component**<br>The storage component implements data access, data reduction, transactions, snapshots, database encryption, data combination, and conflict resolution.
The synchronization component interacts with the storage component and the communication adaptation layer to maintain data consistency between online devices. It synchronizes data generated on the local device to other devices and merges data from other devices into the local device. - **Synchronization component**<br>The synchronization component interacts with the storage component and the communication adaptation layer to maintain data consistency between online devices. It synchronizes data generated on the local device to other devices and merges data from other devices into the local device.
- **Communication adaptation layer**
The communication adaptation layer calls APIs of the underlying public communication layer to create and connect to communication channels, receive device online and offline messages, update metadata of the connected and disconnected devices, send device online and offline messages to the synchronization component. The synchronization component updates the list of connected devices, and calls the APIs of the communication adaption layer to encapsulate data and send the data to the connected devices.
- **Communication adaptation layer**<br>The communication adaptation layer calls APIs of the underlying public communication layer to create and connect to communication channels, receive device online and offline messages, update metadata of the connected and disconnected devices, send device online and offline messages to the synchronization component. The synchronization component updates the list of connected devices, and calls the APIs of the communication adaption layer to encapsulate data and send the data to the connected devices.
Applications call the DDS APIs to create, access, and subscribe to distributed databases. The APIs store data to the storage component based on the capabilities provided by the service component. The storage component interacts with the synchronization component to synchronize data. The synchronization component uses the communication adaptation layer to synchronize data to remote devices, which update the data in the storage component and provide the data for applications through service APIs. Applications call the DDS APIs to create, access, and subscribe to distributed databases. The APIs store data to the storage component based on the capabilities provided by the service component. The storage component interacts with the synchronization component to synchronize data. The synchronization component uses the communication adaptation layer to synchronize data to remote devices, which update the data in the storage component and provide the data for applications through service APIs.
**Figure 1** How DDS works<a name="fig9151258063"></a>
**Figure 1** How DDS works
![](figures/en-us_image_0000001183386164.png) ![](figures/en-us_image_0000001183386164.png)
## Constraints ## Constraints
- The DDS supports the KV data model only. It does not support foreign keys or triggers of the relational database. - The DDS supports the KV data model only. It does not support foreign keys or triggers of the relational database.
- The KV data model specifications supported by the DDS are as follows: - The KV data model specifications supported by the DDS are as follows:
- For each record in a device KV store, the key must be less than or equal to 896 bytes and the value be less than 4 MB. - For each record in a device KV store, the key must be less than or equal to 896 bytes and the value be less than 4 MB.
- For each record in a single KV store, the key must be less than or equal to 1 KB and the value be less than 4 MB. - For each record in a single KV store, the key must be less than or equal to 1 KB and the value be less than 4 MB.
- An application can open a maximum of 16 KV stores simultaneously. - An application can open a maximum of 16 KV stores simultaneously.
- The data that needs to be synchronized between devices should be stored in distributed databases rather than local databases. - The data that needs to be synchronized between devices should be stored in distributed databases rather than local databases.
- The DDS does not support customized conflict resolution policies. - The DDS does not support customized conflict resolution policies.
- The maximum number of access requests to the KvStore API is 1000 per second and 10000 per minute. The maximum number of access requests to the KvManager API is 50 per second and 500 per minute. - The maximum number of access requests to the KvStore API is 1000 per second and 10000 per minute. The maximum number of access requests to the KvManager API is 50 per second and 500 per minute.
- Blocking operations, such as modifying UI components, are not allowed in the distributed database event callback.
- Blocking operations, such as modifying UI components, are not allowed in the distributed database event callback.
...@@ -196,14 +196,38 @@ Table 15 Transaction APIs ...@@ -196,14 +196,38 @@ Table 15 Transaction APIs
(3) Create an RDB store. (3) Create an RDB store.
The sample code is as follows: FA model:
```js ```js
import data_rdb from '@ohos.data.rdb' import data_rdb from '@ohos.data.rdb'
// Obtain the context.
import featureAbility from '@ohos.ability.featureAbility'
let context = featureAbility.getContext()
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = { name: "RdbTest.db" }
data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(CREATE_TABLE_TEST)
console.info('create table done.')
})
```
Stage model:
```ts
import data_rdb from '@ohos.data.rdb'
// Obtain the context.
import Ability from '@ohos.application.Ability'
let context = null
class MainAbility extends Ability {
onWindowStageCreate(windowStage) {
context = this.context
}
}
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = { name: "rdbstore.db" } const STORE_CONFIG = { name: "rdbstore.db" }
data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(CREATE_TABLE_TEST) rdbStore.executeSql(CREATE_TABLE_TEST)
console.info('create table done.') console.info('create table done.')
}) })
......
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
## Implementing Page Redirection ## Implementing Page Redirection
You can implement page redirection through the page router, which finds the target page based on the page URL. Import the **router** module and then perform the steps below: You can implement page redirection through the [page router](../reference/apis/js-apis-router.md#routerpush), which finds the target page based on the page URL. Import the **router** module and then perform the steps below:
1. Implement redirection from the first page to the second page. 1. Implement redirection from the first page to the second page.
......
...@@ -185,7 +185,7 @@ ...@@ -185,7 +185,7 @@
## Implementing Page Redirection ## Implementing Page Redirection
You can implement page redirection through the page router, which finds the target page based on the page URL. Import the **router** module and then perform the steps below: You can implement page redirection through the [page router](../reference/apis/js-apis-router.md#routerpush), which finds the target page based on the page URL. Import the **router** module and then perform the steps below:
1. Implement redirection from the first page to the second page. 1. Implement redirection from the first page to the second page.
......
...@@ -181,7 +181,7 @@ ...@@ -181,7 +181,7 @@
## Implementing Page Redirection ## Implementing Page Redirection
You can implement page redirection through the [page router](../ui/ui-js-building-ui-routes.md), which finds the target page based on the page URL. Import the **router** module and then perform the steps below: You can implement page redirection through the [page router](../reference/apis/js-apis-router.md#routerpush), which finds the target page based on the page URL. Import the **router** module and then perform the steps below:
1. Implement redirection from the first page to the second page. 1. Implement redirection from the first page to the second page.
......
...@@ -146,6 +146,7 @@ ...@@ -146,6 +146,7 @@
- [@ohos.privacyManager](js-apis-privacyManager.md) - [@ohos.privacyManager](js-apis-privacyManager.md)
- [@ohos.security.huks ](js-apis-huks.md) - [@ohos.security.huks ](js-apis-huks.md)
- [@ohos.userIAM.userAuth ](js-apis-useriam-userauth.md) - [@ohos.userIAM.userAuth ](js-apis-useriam-userauth.md)
- [@ohos.userIAM.faceAuth](js-apis-useriam-faceauth.md)
- [@system.cipher](js-apis-system-cipher.md) - [@system.cipher](js-apis-system-cipher.md)
- Data Management - Data Management
......
...@@ -6,8 +6,8 @@ This module provides APIs for accessing ability-specific resources. You can use ...@@ -6,8 +6,8 @@ This module provides APIs for accessing ability-specific resources. You can use
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module can be used only in the stage model. > - The APIs of this module can be used only in the stage model.
## Usage ## Usage
......
...@@ -4,12 +4,12 @@ The **wantConstant** module provides the actions, entities, and flags used in ** ...@@ -4,12 +4,12 @@ The **wantConstant** module provides the actions, entities, and flags used in **
> **NOTE** > **NOTE**
> >
> The initial APIs of this module are supported since API 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
import wantConstant from '@ohos.ability.wantConstant' import wantConstant from '@ohos.ability.wantConstant';
``` ```
## wantConstant.Action ## wantConstant.Action
...@@ -46,8 +46,13 @@ Enumerates the action constants of the **Want** object. ...@@ -46,8 +46,13 @@ Enumerates the action constants of the **Want** object.
| ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | Action of selecting a file. | | ACTION_FILE_SELECT<sup>7+</sup> | ohos.action.fileSelect | Action of selecting a file. |
| PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. | | PARAMS_STREAM<sup>7+</sup> | ability.params.stream | URI of the data stream associated with the target when the data is sent. |
| ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | Action of providing the OAuth service. | | ACTION_APP_ACCOUNT_OAUTH <sup>8+</sup> | ohos.account.appAccount.action.oauth | Action of providing the OAuth service. |
| ACTION_MARKER_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | Action of downloading an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. | | ACTION_MARKET_DOWNLOAD <sup>9+</sup> | ohos.want.action.marketDownload | Action of downloading an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| ACTION_MARKET_CROWDTEST <sup>9+</sup> | ohos.want.action.marketCrowdTest | Action of crowdtesting an application from the application market.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_SANDBOX<sup>9+</sup> |ohos.dlp.params.sandbox | Action of obtaining the sandbox flag.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_BUNDLE_NAME<sup>9+</sup> |ohos.dlp.params.bundleName |Action of obtaining the DLP bundle name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_MODULE_NAME<sup>9+</sup> |ohos.dlp.params.moduleName |Action of obtaining the DLP module name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_ABILITY_NAME<sup>9+</sup> |ohos.dlp.params.abilityName |Action of obtaining the DLP ability name.<br>**System API**: This is a system API and cannot be called by third-party applications. |
| DLP_PARAMS_INDEX<sup>9+</sup> |ohos.dlp.params.index |Action of obtaining the DLP index.<br>**System API**: This is a system API and cannot be called by third-party applications. |
## wantConstant.Entity ## wantConstant.Entity
......
...@@ -99,7 +99,7 @@ export default class MyWindowExtensionAbility extends WindowExtensionAbility { ...@@ -99,7 +99,7 @@ export default class MyWindowExtensionAbility extends WindowExtensionAbility {
onWindowReady(window) { onWindowReady(window) {
window.loadContent('WindowExtAbility/pages/index1').then(() => { window.loadContent('WindowExtAbility/pages/index1').then(() => {
window.getProperties().then((pro) => { window.getProperties().then((pro) => {
console.log("WindowExtension " + JSON.stringify(pro)); console.log('WindowExtension ' + JSON.stringify(pro));
}) })
window.show(); window.show();
}) })
......
...@@ -4,7 +4,7 @@ The **Ability** module manages the ability lifecycle and context, such as creati ...@@ -4,7 +4,7 @@ The **Ability** module manages the ability lifecycle and context, such as creati
This module provides the following common ability-related functions: This module provides the following common ability-related functions:
- [Caller](#caller): implements sending of sequenceable data to the target ability when an ability (caller) invokes the target ability (callee). - [Caller](#caller): implements sending of sequenceable data to the target ability when an ability (caller ability) invokes the target ability (callee ability).
- [Callee](#callee): implements callbacks for registration and deregistration of caller notifications. - [Callee](#callee): implements callbacks for registration and deregistration of caller notifications.
> **NOTE** > **NOTE**
...@@ -39,10 +39,10 @@ Called to initialize the service logic when an ability is created. ...@@ -39,10 +39,10 @@ Called to initialize the service logic when an ability is created.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Information related to this ability, including the ability name and bundle name.| | want | [Want](js-apis-application-Want.md) | Yes| Information related to this ability, including the ability name and bundle name.|
| param | AbilityConstant.LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.| | param | AbilityConstant.LaunchParam | Yes| Parameters for starting the ability, and the reason for the last abnormal exit.|
**Example** **Example**
...@@ -65,9 +65,9 @@ Called when a **WindowStage** is created for this ability. ...@@ -65,9 +65,9 @@ Called when a **WindowStage** is created for this ability.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| windowStage | window.WindowStage | Yes| **WindowStage** information.| | windowStage | window.WindowStage | Yes| **WindowStage** information.|
**Example** **Example**
...@@ -109,9 +109,9 @@ Called when the **WindowStage** is restored during the migration of this ability ...@@ -109,9 +109,9 @@ Called when the **WindowStage** is restored during the migration of this ability
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| windowStage | window.WindowStage | Yes| **WindowStage** information.| | windowStage | window.WindowStage | Yes| **WindowStage** information.|
**Example** **Example**
...@@ -191,15 +191,15 @@ Called to save data during the ability migration preparation process. ...@@ -191,15 +191,15 @@ Called to save data during the ability migration preparation process.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| wantParam | {[key:&nbsp;string]:&nbsp;any} | Yes| **want** parameter.| | wantParam | {[key:&nbsp;string]:&nbsp;any} | Yes| **want** parameter.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| AbilityConstant.OnContinueResult | Continuation result.| | AbilityConstant.OnContinueResult | Continuation result.|
**Example** **Example**
...@@ -225,20 +225,17 @@ Called when the ability startup mode is set to singleton. ...@@ -225,20 +225,17 @@ Called when the ability startup mode is set to singleton.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| want | [Want](js-apis-application-Want.md) | Yes| Want parameters, such as the ability name and bundle name.| | want | [Want](js-apis-application-Want.md) | Yes| Want parameters, such as the ability name and bundle name.|
| launchParams | AbilityConstant.LaunchParam | Yes| Reason for the ability startup and the last abnormal exit.| | launchParams | AbilityConstant.LaunchParam | Yes| Reason for the ability startup and the last abnormal exit.|
**Example** **Example**
```js ```js
class myAbility extends Ability { class myAbility extends Ability {
onNewWant(want, launchParams) { onNewWant(want) {
console.log('onNewWant, want:' + want.abilityName); console.log('onNewWant, want:' + want.abilityName);
if (launchParams.launchReason === AbilityConstant.LaunchReason.CONTINUATION) {
console.log('onNewWant, launchReason is continuation');
}
} }
} }
``` ```
...@@ -254,9 +251,9 @@ Called when the configuration of the environment where the ability is running is ...@@ -254,9 +251,9 @@ Called when the configuration of the environment where the ability is running is
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| config | [Configuration](js-apis-configuration.md) | Yes| New configuration.| | config | [Configuration](js-apis-configuration.md) | Yes| New configuration.|
**Example** **Example**
...@@ -278,9 +275,9 @@ Dumps client information. ...@@ -278,9 +275,9 @@ Dumps client information.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| params | Array\<string> | Yes| Parameters in the form of a command.| | params | Array\<string> | Yes| Parameters in the form of a command.|
**Example** **Example**
...@@ -293,11 +290,35 @@ Dumps client information. ...@@ -293,11 +290,35 @@ Dumps client information.
} }
``` ```
## Ability.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| level | [AbilityConstant.MemoryLevel](js-apis-application-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.|
**Example**
```js
class myAbility extends Ability {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
}
```
## Caller ## Caller
Implements sending of sequenceable data to the target ability when an ability (caller) invokes the target ability (callee). Implements sending of sequenceable data to the target ability when an ability (caller ability) invokes the target ability (callee ability).
## Caller.call ## Caller.call
...@@ -310,16 +331,16 @@ Sends sequenceable data to the target ability. ...@@ -310,16 +331,16 @@ Sends sequenceable data to the target ability.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.| | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
| data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.| | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return a response.| | Promise&lt;void&gt; | Promise used to return a response.|
**Example** **Example**
...@@ -383,16 +404,16 @@ Sends sequenceable data to the target ability and obtains the sequenceable data ...@@ -383,16 +404,16 @@ Sends sequenceable data to the target ability and obtains the sequenceable data
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.| | method | string | Yes| Notification message string negotiated between the two abilities. The message is used to instruct the callee to register a function to receive the sequenceable data.|
| data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.| | data | rpc.Sequenceable | Yes| Sequenceable data. You need to customize the data.|
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;rpc.MessageParcel&gt; | Promise used to return the sequenceable data from the target ability.| | Promise&lt;rpc.MessageParcel&gt; | Promise used to return the sequenceable data from the target ability.|
**Example** **Example**
...@@ -492,9 +513,9 @@ Registers a callback that is invoked when the stub on the target ability is disc ...@@ -492,9 +513,9 @@ Registers a callback that is invoked when the stub on the target ability is disc
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | OnReleaseCallBack | Yes| Callback used for the **onRelease** API.| | callback | OnReleaseCallBack | Yes| Callback used for the **onRelease** API.|
**Example** **Example**
...@@ -540,12 +561,13 @@ Registers a caller notification callback, which is invoked when the target abili ...@@ -540,12 +561,13 @@ Registers a caller notification callback, which is invoked when the target abili
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes| Notification message string negotiated between the two abilities.| | method | string | Yes| Notification message string negotiated between the two abilities.|
| callback | CalleeCallBack | Yes| JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails.| | callback | CalleeCallBack | Yes| JS notification synchronization callback of the **rpc.MessageParcel** type. The callback must return at least one empty **rpc.Sequenceable** object. Otherwise, the function execution fails.|
**Example** **Example**
```js ```js
import Ability from '@ohos.application.Ability'; import Ability from '@ohos.application.Ability';
class MyMessageAble{ class MyMessageAble{
...@@ -595,9 +617,9 @@ Deregisters a caller notification callback, which is invoked when the target abi ...@@ -595,9 +617,9 @@ Deregisters a caller notification callback, which is invoked when the target abi
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| method | string | Yes| Registered notification message string.| | method | string | Yes| Registered notification message string.|
**Example** **Example**
...@@ -622,8 +644,7 @@ Deregisters a caller notification callback, which is invoked when the target abi ...@@ -622,8 +644,7 @@ Deregisters a caller notification callback, which is invoked when the target abi
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| (msg: string) | function | Yes| No| Prototype of the listener function registered by the caller.| | (msg: string) | function | Yes| No| Prototype of the listener function registered by the caller.|
## CalleeCallBack
## CalleeCallBack
(indata: rpc.MessageParcel): rpc.Sequenceable; (indata: rpc.MessageParcel): rpc.Sequenceable;
......
...@@ -65,7 +65,7 @@ Enumerates ability continuation results. ...@@ -65,7 +65,7 @@ Enumerates ability continuation results.
## AbilityConstant.WindowMode ## AbilityConstant.WindowMode
Enumerates the window modes when an ability is started. Enumerates the window modes in which an ability can be displayed at startup.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -76,3 +76,15 @@ Enumerates the window modes when an ability is started. ...@@ -76,3 +76,15 @@ Enumerates the window modes when an ability is started.
| WINDOW_MODE_SPLIT_PRIMARY | 100 | The ability is displayed in the primary window in split-screen mode. | | WINDOW_MODE_SPLIT_PRIMARY | 100 | The ability is displayed in the primary window in split-screen mode. |
| WINDOW_MODE_SPLIT_SECONDARY | 101 | The ability is displayed in the secondary window in split-screen mode. | | WINDOW_MODE_SPLIT_SECONDARY | 101 | The ability is displayed in the secondary window in split-screen mode. |
| WINDOW_MODE_FLOATING | 102 | The ability is displayed in a floating window.| | WINDOW_MODE_FLOATING | 102 | The ability is displayed in a floating window.|
## AbilityConstant.MemoryLevel
Enumerates the memory levels.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Value| Description |
| --- | --- | --- |
| MEMORY_LEVEL_MODERATE | 0 | Moderate memory usage. |
| MEMORY_LEVEL_LOW | 1 | Low memory usage. |
| MEMORY_LEVEL_CRITICAL | 2 | High memory usage. |
...@@ -875,3 +875,265 @@ abilityDelegator.finishTest(msg, 0).then(() => { ...@@ -875,3 +875,265 @@ abilityDelegator.finishTest(msg, 0).then(() => {
console.info("finishTest promise"); console.info("finishTest promise");
}); });
``` ```
### addAbilityStageMonitor<sup>9+</sup>
addAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback\<void>): void;
Adds an **AbilityStageMonitor** instance to monitor the lifecycle state changes of an ability stage. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ |
| monitor | [AbilityStageMonitor](#abilitystagemonitor) | Yes | [AbilityStageMonitor](#abilitystagemonitor) instance.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
```js
var abilityDelegator;
var monitor = {
moduleName: "moduleName",
srcEntrance: "srcEntrance",
}
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityStageMonitor(monitor, (err : any) => {
console.info("addAbilityStageMonitor callback");
});
```
### addAbilityStageMonitor<sup>9+</sup>
addAbilityStageMonitor(monitor: AbilityStageMonitor): Promise\<void>;
Adds an **AbilityStageMonitor** instance to monitor the lifecycle state changes of an ability stage. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| monitor | [AbilityStageMonitor](#abilitystagemonitor) | Yes | [AbilityStageMonitor](#abilitystagemonitor) instance.|
**Return value**
| Type | Description |
| -------------- | ------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var abilityDelegator;
var monitor = {
moduleName: "moduleName",
srcEntrance: "srcEntrance",
}
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityStageMonitor(monitor).then(() => {
console.info("addAbilityStageMonitor promise");
});
```
### removeAbilityStageMonitor<sup>9+</sup>
removeAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback\<void>): void;
Removes an **AbilityStageMonitor** instance from the application memory. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ |
| monitor | [AbilityStageMonitor](#abilitystagemonitor) | Yes | [AbilityStageMonitor](#abilitystagemonitor) instance.|
| callback | AsyncCallback\<void> | Yes | Callback used to return the result. |
**Example**
```js
var abilityDelegator;
var monitor = {
moduleName: "moduleName",
srcEntrance: "srcEntrance",
}
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.removeAbilityStageMonitor(monitor, (err : any) => {
console.info("removeAbilityStageMonitor callback");
});
```
### removeAbilityStageMonitor<sup>9+</sup>
removeAbilityStageMonitor(monitor: AbilityStageMonitor): Promise\<void>;
Removes an **AbilityStageMonitor** object from the application memory. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| monitor | [AbilityStageMonitor](#abilitystagemonitor) | Yes | [AbilityStageMonitor](#abilitystagemonitor) instance.|
**Return value**
| Type | Description |
| -------------- | ------------------- |
| Promise\<void> | Promise used to return the result.|
**Example**
```js
var abilityDelegator;
var monitor = {
moduleName: "moduleName",
srcEntrance: "srcEntrance",
}
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.removeAbilityStageMonitor(monitor).then(() => {
console.info("removeAbilityStageMonitor promise");
});
```
### waitAbilityStageMonitor<sup>9+</sup>
waitAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback\<AbilityStage>): void;
Waits for an **AbilityStage** instance that matches the conditions set in an **AbilityStageMonitor** instance and returns the **AbilityStage** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ |
| monitor | [AbilityStageMonitor](#abilitystagemonitor) | Yes | [AbilityStageMonitor](#abilitystagemonitor) instance.|
| callback | AsyncCallback\<AbilityStage> | Yes | Callback used to return the result. If the operation is successful, an **AbilityStage** instance is returned. Otherwise, no value is returned. |
**Example**
```js
var abilityDelegator;
function onAbilityCreateCallback(data) {
console.info("onAbilityCreateCallback");
}
var monitor = {
moduleName: "moduleName",
srcEntrance: "srcEntrance",
}
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityStageMonitor(monitor, (err : any, data : any) => {
console.info("waitAbilityStageMonitor callback");
});
```
### waitAbilityStageMonitor<sup>9+</sup>
waitAbilityStageMonitor(monitor: AbilityStageMonitor, timeout?: number): Promise\<AbilityStage>;
Waits for an **AbilityStage** instance that matches the conditions set in an **AbilityStageMonitor** instance and returns the **AbilityStage** instance. This API uses a promise to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| monitor | [AbilityStageMonitor](#abilitystagemonitor) | Yes | [AbilityStageMonitor](#abilitystagemonitor) instance.|
| timeout | number | No | Maximum waiting time, in milliseconds.|
**Return value**
| Type | Description |
| -------------- | ------------------- |
| Promise\<AbilityStage> | Promise used to return the result. If the operation is successful, an **AbilityStage** instance is returned. Otherwise, no value is returned.|
**Example**
```js
var abilityDelegator;
function onAbilityCreateCallback(data) {
console.info("onAbilityCreateCallback");
}
var monitor = {
moduleName: "moduleName",
srcEntrance: "srcEntrance",
}
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityStageMonitor(monitor).then((data : any) => {
console.info("waitAbilityStageMonitor promise");
});
```
### waitAbilityStageMonitor<sup>9+</sup>
waitAbilityStageMonitor(monitor: AbilityStageMonitor, timeout: number, callback: AsyncCallback\<AbilityStage>): void;
Waits a period of time for an **AbilityStage** instance that matches the conditions set in an **AbilityStageMonitor** instance and returns the **AbilityStage** instance. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| monitor | [AbilityStageMonitor](#abilitystagemonitor) | Yes | [AbilityStageMonitor](#abilitystagemonitor) instance.|
| timeout | number | No | Maximum waiting time, in milliseconds.|
| callback | AsyncCallback\<AbilityStage> | Yes | Callback used to return the result. If the operation is successful, an **AbilityStage** instance is returned. Otherwise, no value is returned. |
**Example**
```js
var abilityDelegator;
var timeout = 100;
function onAbilityCreateCallback(data) {
console.info("onAbilityCreateCallback");
}
var monitor = {
moduleName: "moduleName",
srcEntrance: "srcEntrance",
}
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityStageMonitor(monitor, timeout, (err : any, data : any) => {
console.info("waitAbilityStageMonitor callback");
});
```
## AbilityStageMonitor
Provides conditions for matching **AbilityStage** instances. The most recently matched **AbilityStage** instance is saved in an **AbilityStageMonitor** instance.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Type | Readable| Writable| Description |
| ------------------------------------------------------------ | -------- | ---- | ---- | ------------------------------------------------------------ |
| moduleName<sup>9+</sup> | string | Yes | Yes | Module name of the **AbilityStage** instance.|
| srcEntrance<sup>9+</sup> | string | Yes | Yes | Source path of the **AbilityStage** instance.|
...@@ -11,7 +11,7 @@ The **AbilityDelegatorArgs** module provides a global register to store the regi ...@@ -11,7 +11,7 @@ The **AbilityDelegatorArgs** module provides a global register to store the regi
The ability delegator arguments are obtained by calling **getArguments** in **AbilityDelegatorRegistry**. The ability delegator arguments are obtained by calling **getArguments** in **AbilityDelegatorRegistry**.
```js ```js
import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry' import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry';
var args = AbilityDelegatorRegistry.getArguments(); var args = AbilityDelegatorRegistry.getArguments();
``` ```
...@@ -24,7 +24,7 @@ Describes the ability delegator arguments. ...@@ -24,7 +24,7 @@ Describes the ability delegator arguments.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------- | ---------------------- | ---- | ---- | ------------------------------------------------------------ | | ------------------- | ---------------------- | ---- | ---- | ------------------------------------------------------------ |
| bundleName | string | Yes | Yes | Bundle name of the application to test. | | bundleName | string | Yes | Yes | Bundle name of the application to test.|
| parameters | {[key:string]: string} | Yes | Yes | Parameters of the unit test that is started currently. | | parameters | {[key:string]: string} | Yes | Yes | Parameters of the unit test that is started currently.|
| testCaseNames | string | Yes | Yes | Test case names. | | testCaseNames | string | Yes | Yes | Test case names.|
| testRunnerClassName | string | Yes | Yes | Names of the test case executors. | | testRunnerClassName | string | Yes | Yes | Names of the test case executors.|
...@@ -89,6 +89,31 @@ Called when the global configuration is updated. ...@@ -89,6 +89,31 @@ Called when the global configuration is updated.
} }
} }
``` ```
## AbilityStage.onMemoryLevel
onMemoryLevel(level: AbilityConstant.MemoryLevel): void;
Called when the system has decided to adjust the memory level. For example, this API can be used when there is not enough memory to run as many background processes as possible.
**System capability**: SystemCapability.Ability.AbilityRuntime.AbilityCore
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| level | [AbilityConstant.MemoryLevel](js-apis-application-abilityConstant.md#abilityconstantmemorylevel) | Yes| Memory level that indicates the memory usage status. When the specified memory level is reached, a callback will be invoked and the system will start adjustment.|
**Example**
```js
class MyAbilityStage extends AbilityStage {
onMemoryLevel(level) {
console.log('onMemoryLevel, level:' + JSON.stringify(level));
}
}
```
## AbilityStage.context ## AbilityStage.context
context: AbilityStageContext; context: AbilityStageContext;
......
...@@ -22,9 +22,9 @@ Checks whether this application is undergoing a stability test. This API uses an ...@@ -22,9 +22,9 @@ Checks whether this application is undergoing a stability test. This API uses an
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
...@@ -46,9 +46,9 @@ Checks whether this application is undergoing a stability test. This API uses a ...@@ -46,9 +46,9 @@ Checks whether this application is undergoing a stability test. This API uses a
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.| | Promise&lt;boolean&gt; | Promise used to return the result. If the application is undergoing a stability test, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
...@@ -72,9 +72,9 @@ Checks whether this application is running on a RAM constrained device. This API ...@@ -72,9 +72,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| | Promise&lt;boolean&gt; | Promise used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
...@@ -96,9 +96,9 @@ Checks whether this application is running on a RAM constrained device. This API ...@@ -96,9 +96,9 @@ Checks whether this application is running on a RAM constrained device. This API
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.| | callback | AsyncCallback&lt;boolean&gt; | No| Callback used to return whether the application is running on a RAM constrained device. If the application is running on a RAM constrained device, **true** will be returned; otherwise, **false** will be returned.|
**Example** **Example**
...@@ -119,9 +119,9 @@ Obtains the memory size of this application. This API uses a promise to return t ...@@ -119,9 +119,9 @@ Obtains the memory size of this application. This API uses a promise to return t
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Size of the application memory.| | Promise&lt;number&gt; | Size of the application memory.|
**Example** **Example**
...@@ -143,9 +143,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb ...@@ -143,9 +143,9 @@ Obtains the memory size of this application. This API uses an asynchronous callb
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.| | callback | AsyncCallback&lt;number&gt; | No| Size of the application memory.|
**Example** **Example**
...@@ -157,14 +157,12 @@ Obtains the memory size of this application. This API uses an asynchronous callb ...@@ -157,14 +157,12 @@ Obtains the memory size of this application. This API uses an asynchronous callb
``` ```
## appManager.getProcessRunningInfos<sup>(deprecated)</sup> ## appManager.getProcessRunningInfos<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](#appmanagergetprocessrunninginformation9) instead.
getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>; getProcessRunningInfos(): Promise\<Array\<ProcessRunningInfo>>;
Obtains information about the running processes. This API uses a promise to return the result. Obtains information about the running processes. This API uses a promise to return the result.
> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](#appmanagergetprocessrunninginformation9) instead.
**Required permissions**: ohos.permission.GET_RUNNING_INFO **Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -187,14 +185,12 @@ Obtains information about the running processes. This API uses a promise to retu ...@@ -187,14 +185,12 @@ Obtains information about the running processes. This API uses a promise to retu
## appManager.getProcessRunningInfos<sup>(deprecated)</sup> ## appManager.getProcessRunningInfos<sup>(deprecated)</sup>
> **NOTE**
>
> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](#appmanagergetprocessrunninginformation9-1) instead.
getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void; getProcessRunningInfos(callback: AsyncCallback\<Array\<ProcessRunningInfo>>): void;
Obtains information about the running processes. This API uses an asynchronous callback to return the result. Obtains information about the running processes. This API uses an asynchronous callback to return the result.
> This API is deprecated since API version 9. You are advised to use [appManager.getProcessRunningInformation<sup>9+</sup>](#appmanagergetprocessrunninginformation9-1) instead.
**Required permissions**: ohos.permission.GET_RUNNING_INFO **Required permissions**: ohos.permission.GET_RUNNING_INFO
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Core
...@@ -228,7 +224,7 @@ Obtains information about the running processes. This API uses a promise to retu ...@@ -228,7 +224,7 @@ Obtains information about the running processes. This API uses a promise to retu
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise\<Array\<ProcessRunningInformation>> | Promise used to return the process information.| | Promise\<Array\<[ProcessRunningInformation](#processrunninginformation)>> | Promise used to return the process information.|
**Example** **Example**
...@@ -254,7 +250,7 @@ Obtains information about the running processes. This API uses an asynchronous c ...@@ -254,7 +250,7 @@ Obtains information about the running processes. This API uses an asynchronous c
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback\<Array\<ProcessRunningInformation>> | No| Callback used to return the process information.| | callback | AsyncCallback\<Array\<[ProcessRunningInformation](#processrunninginformation)>> | No| Callback used to return the process information.|
**Example** **Example**
...@@ -269,7 +265,7 @@ Obtains information about the running processes. This API uses an asynchronous c ...@@ -269,7 +265,7 @@ Obtains information about the running processes. This API uses an asynchronous c
registerApplicationStateObserver(observer: ApplicationStateObserver): number; registerApplicationStateObserver(observer: ApplicationStateObserver): number;
Registers an observer to listen for the state of all applications. Registers an observer to listen for the state changes of all applications.
**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER **Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
...@@ -307,9 +303,9 @@ Registers an observer to listen for the state of all applications. ...@@ -307,9 +303,9 @@ Registers an observer to listen for the state of all applications.
## appManager.registerApplicationStateObserver<sup>9+</sup> ## appManager.registerApplicationStateObserver<sup>9+</sup>
registerApplicationStateObserver(observer: ApplicationStateObserver, bundleNameList: Array<string>): number; registerApplicationStateObserver(observer: ApplicationStateObserver, bundleNameList: Array\<string>): number;
Registers an observer to listen for the state of a specified application. Registers an observer to listen for the state changes of a specified application.
**Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER **Required permissions**: ohos.permission.RUNNING_STATE_OBSERVER
...@@ -322,7 +318,7 @@ Registers an observer to listen for the state of a specified application. ...@@ -322,7 +318,7 @@ Registers an observer to listen for the state of a specified application.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| observer | [ApplicationStateObserver](#applicationstateobserver) | No| Numeric code of the observer.| | observer | [ApplicationStateObserver](#applicationstateobserver) | No| Numeric code of the observer.|
| bundleNameList | Array<string> | No| **bundleName** array to be registered for listening. The maximum value is 128.| | bundleNameList | Array<string> | No| **bundleName** array of the application. A maximum of 128 bundle names can be passed.|
**Example** **Example**
...@@ -491,10 +487,10 @@ Kills a process by bundle name and account ID. This API uses a promise to return ...@@ -491,10 +487,10 @@ Kills a process by bundle name and account ID. This API uses a promise to return
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name of an application.| | bundleName | string | Yes| Bundle name of an application.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).| | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
**Example** **Example**
...@@ -525,11 +521,11 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal ...@@ -525,11 +521,11 @@ Kills a process by bundle name and account ID. This API uses an asynchronous cal
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| bundleName | string | Yes| Bundle name of an application.| | bundleName | string | Yes| Bundle name of an application.|
| accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).| | accountId | number | Yes| ID of a system account. For details, see [getCreatedOsAccountsCount](js-apis-osAccount.md#getosaccountlocalidfromprocess).|
| callback | AsyncCallback\<void\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes| Callback used to return the result.|
**Example** **Example**
...@@ -708,9 +704,14 @@ Called when the application state changes. ...@@ -708,9 +704,14 @@ Called when the application state changes.
**Example** **Example**
```js ```js
import ApplicationStateObserver from '@ohos.application.ApplicationStateObserver' var applicationStateObserver = {
const foregroundApplicationInfo = ApplicationStateObserver.onForegroundApplicationChanged(); onForegroundApplicationChanged(appStateData) {
console.log('-------- foregroundApplicationInfo: ---------', foregroundApplicationInfo); console.log('------------ onForegroundApplicationChanged -----------', appStateData);
}
}
const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
``` ```
## ApplicationStateObserver.onAbilityStateChanged<sup>8+</sup> ## ApplicationStateObserver.onAbilityStateChanged<sup>8+</sup>
...@@ -732,9 +733,13 @@ Called when the ability state changes. ...@@ -732,9 +733,13 @@ Called when the ability state changes.
**Example** **Example**
```js ```js
import ApplicationStateObserver from '@ohos.application.ApplicationStateObserver' var applicationStateObserver = {
const abilityStateChangedInfo = ApplicationStateObserver.onAbilityStateChanged(); onAbilityStateChanged(abilityStateData) {
console.log('-------- abilityStateChangedInfo: ---------', abilityStateChangedInfo); console.log('------------ onAbilityStateChanged -----------', abilityStateData);
}
}
const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
``` ```
## ApplicationStateObserver.onProcessCreated<sup>8+</sup> ## ApplicationStateObserver.onProcessCreated<sup>8+</sup>
...@@ -756,9 +761,13 @@ Called when a process is created. ...@@ -756,9 +761,13 @@ Called when a process is created.
**Example** **Example**
```js ```js
import ApplicationStateObserver from '@ohos.application.ApplicationStateObserver' var applicationStateObserver = {
const processCreatedInfo = ApplicationStateObserver.onProcessCreated(); onProcessCreated(processData) {
console.log('-------- processCreatedInfo: ---------', processCreatedInfo); console.log('------------ onProcessCreated -----------', processData);
}
}
const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
``` ```
## ApplicationStateObserver.onProcessDied<sup>8+</sup> ## ApplicationStateObserver.onProcessDied<sup>8+</sup>
...@@ -775,14 +784,46 @@ Called when a process is terminated. ...@@ -775,14 +784,46 @@ Called when a process is terminated.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| processData | ProcessData | No| Process information.| | processData | [ProcessData](#processdata) | No| Process information.|
**Example** **Example**
```js ```js
import ApplicationStateObserver from '@ohos.application.ApplicationStateObserver' var applicationStateObserver = {
const processDiedInfo = ApplicationStateObserver.onProcessDied(); onProcessDied(processData) {
console.log('-------- processDiedInfo: ---------', processDiedInfo); console.log('------------ onProcessDied -----------', processData);
}
}
const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
```
## ApplicationStateObserver.onProcessStateChanged<sup>9+</sup>
onProcessStateChanged(processData: ProcessData): void;
Called when the process state changes.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| processData | [ProcessData](#processdata) | No| Process information.|
**Example**
```js
var applicationStateObserver = {
onProcessStateChanged(processData) {
console.log('------------ onProcessStateChanged -----------', processData);
}
}
const observerCode = app.registerApplicationStateObserver(applicationStateObserver);
console.log('-------- observerCode: ---------', observerCode);
``` ```
## AppStateData ## AppStateData
...@@ -815,7 +856,7 @@ console.log('-------- processDiedInfo: ---------', processDiedInfo); ...@@ -815,7 +856,7 @@ console.log('-------- processDiedInfo: ---------', processDiedInfo);
## ProcessData ## ProcessData
**System capability**: SystemCapability.Ability.AbilityRuntime.Mission **System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
...@@ -824,19 +865,19 @@ console.log('-------- processDiedInfo: ---------', processDiedInfo); ...@@ -824,19 +865,19 @@ console.log('-------- processDiedInfo: ---------', processDiedInfo);
| pid<sup>8+</sup> | number | Yes | No | Process ID. | | pid<sup>8+</sup> | number | Yes | No | Process ID. |
| bundleName<sup>8+</sup> | string | Yes | No | Bundle name of an application. | | bundleName<sup>8+</sup> | string | Yes | No | Bundle name of an application. |
| uid<sup>8+</sup> | number | Yes | No | User ID. | | uid<sup>8+</sup> | number | Yes | No | User ID. |
| isContinuousTask<sup>9+</sup> | boolean | Yes | No | Whether the process is a continuous task. |
| isKeepAlive<sup>9+</sup> | boolean | Yes | No | Whether the process remains active. |
## ProcessRunningInfo ## ProcessRunningInfo
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
| Name | Readable/Writable| Type | Mandatory| Description | | Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ | | ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| pid<sup>9+</sup> | Read only | number | No | Process ID. | | pid<sup>8+</sup> | Read only | number | No | Process ID. |
| uid<sup>9+</sup> | Read only | number | No | User ID.| | uid<sup>8+</sup> | Read only | number | No | User ID.|
| processName<sup>9+</sup> | Read only | string | No | Process name.| | processName<sup>8+</sup> | Read only | string | No | Process name.|
| bundleNames<sup>9+</sup> | Read only | Array\<string> | No | **bundleName** array in the running processes.| | bundleNames<sup>8+</sup> | Read only | Array\<string> | No | **bundleName** array in the running processes.|
## ApplicationStateObserver ## ApplicationStateObserver
...@@ -850,3 +891,44 @@ console.log('-------- processDiedInfo: ---------', processDiedInfo); ...@@ -850,3 +891,44 @@ console.log('-------- processDiedInfo: ---------', processDiedInfo);
| [onAbilityStateChanged<sup>8+</sup>](#applicationstateobserveronabilitystatechanged8) | AsyncCallback\<void> | Yes | No | Callback invoked when the ability state changes. | | [onAbilityStateChanged<sup>8+</sup>](#applicationstateobserveronabilitystatechanged8) | AsyncCallback\<void> | Yes | No | Callback invoked when the ability state changes. |
| [onProcessCreated<sup>8+</sup>](#applicationstateobserveronprocesscreated8) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is created. | | [onProcessCreated<sup>8+</sup>](#applicationstateobserveronprocesscreated8) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is created. |
| [onProcessDied<sup>8+</sup>](#applicationstateobserveronprocessdied8) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is destroyed. | | [onProcessDied<sup>8+</sup>](#applicationstateobserveronprocessdied8) | AsyncCallback\<void> | Yes | No | Callback invoked when a process is destroyed. |
## ProcessRunningInformation
Defines the process running information.
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name | Readable/Writable| Type | Mandatory| Description |
| ----------- | -------- | -------------------- | ---- | ------------------------------------------------------------ |
| pid<sup>9+</sup> | Read only | number | No | Process ID. |
| uid<sup>9+</sup> | Read only | number | No | User ID.|
| processName<sup>9+</sup> | Read only | string | No | Process name.|
| bundleNames<sup>9+</sup> | Read only | Array\<string> | No | **bundleName** array in the running processes.|
## ApplicationState<sup>9+</sup>
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| -------------------- | --- | --------------------------------- |
| STATE_CREATE | 1 | State indicating that the application is being created. |
| STATE_FOREGROUND | 2 | State indicating that the application is running in the foreground. |
| STATE_ACTIVE | 3 | State indicating that the application is active. |
| STATE_BACKGROUND | 4 | State indicating that the application is running in the background. |
| STATE_DESTROY | 5 | State indicating that the application is destroyed. |
## ProcessState<sup>9+</sup>
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name | Value | Description |
| -------------------- | --- | --------------------------------- |
| STATE_CREATE | 1 | State indicating that the process is being created. |
| STATE_FOREGROUND | 2 | State indicating that the process is running in the foreground. |
| STATE_ACTIVE | 3 | State indicating that the process is active. |
| STATE_BACKGROUND | 4 | State indicating that the process is running in the background. |
| STATE_DESTROY | 5 | State indicating that the process is destroyed. |
...@@ -812,7 +812,7 @@ Obtains the zoom ratio range. This API uses an asynchronous callback to return t ...@@ -812,7 +812,7 @@ Obtains the zoom ratio range. This API uses an asynchronous callback to return t
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------ | ---- | ------------------------ | | -------- | ------------------------------ | ---- | ------------------------ |
| callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return the result.| | callback | AsyncCallback<Array<number\>\> | Yes | Callback used to return an array containing the minimum and maximum zoom ratios.|
**Example** **Example**
...@@ -838,7 +838,7 @@ Obtains the zoom ratio range. This API uses a promise to return the result. ...@@ -838,7 +838,7 @@ Obtains the zoom ratio range. This API uses a promise to return the result.
| Type | Description | | Type | Description |
| ------------------------ | ------------------------------------------- | | ------------------------ | ------------------------------------------- |
| Promise<Array<number\>\> | Promise used to return the zoom ratio range.| | Promise<Array<number\>\> | Promise used to return an array containing the minimum and maximum zoom ratios.|
**Example** **Example**
......
...@@ -71,10 +71,6 @@ Provides the event types supported by the **CommonEvent** module. The name and v ...@@ -71,10 +71,6 @@ Provides the event types supported by the **CommonEvent** module. The name and v
| COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | - | Indicates the common event that the credential-encrypted storage has been unlocked for the current user when the device is unlocked after being restarted. | | COMMON_EVENT_USER_UNLOCKED | usual.event.USER_UNLOCKED | - | Indicates the common event that the credential-encrypted storage has been unlocked for the current user when the device is unlocked after being restarted. |
| COMMON_EVENT_USER_STOPPING | usual.event.USER_STOPPING | ohos.permission.INTERACT_ACROSS_USERS | Indicates the common event that the user is going to be stopped. | | COMMON_EVENT_USER_STOPPING | usual.event.USER_STOPPING | ohos.permission.INTERACT_ACROSS_USERS | Indicates the common event that the user is going to be stopped. |
| COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | - | Indicates the common event that the user has been stopped. | | COMMON_EVENT_USER_STOPPED | usual.event.USER_STOPPED | - | Indicates the common event that the user has been stopped. |
| COMMON_EVENT_HWID_LOGIN | common.event.HWID_LOGIN | - | Indicates the common event about a HUAWEI ID login. |
| COMMON_EVENT_HWID_LOGOUT | common.event.HWID_LOGOUT | - | Indicates the common event about a HUAWEI ID logout. |
| COMMON_EVENT_HWID_TOKEN_INVALID | common.event.HWID_TOKEN_INVALID | - | Indicates the common event that the HUAWEI ID is invalid. |
| COMMON_EVENT_HWID_LOGOFF | common.event.HWID_LOGOFF | - | Indicates the common event about a HUAWEI ID logoff. |
| COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | - | Indicates the common event about the Wi-Fi network state, such as enabled and disabled. | | COMMON_EVENT_WIFI_POWER_STATE | usual.event.wifi.POWER_STATE | - | Indicates the common event about the Wi-Fi network state, such as enabled and disabled. |
| COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION | Indicates the common event that the Wi-Fi access point has been scanned and proven to be available. | | COMMON_EVENT_WIFI_SCAN_FINISHED | usual.event.wifi.SCAN_FINISHED | ohos.permission.LOCATION | Indicates the common event that the Wi-Fi access point has been scanned and proven to be available. |
| COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO | Indicates the common event that the Wi-Fi signal strength (RSSI) has changed. | | COMMON_EVENT_WIFI_RSSI_VALUE | usual.event.wifi.RSSI_VALUE | ohos.permission.GET_WIFI_INFO | Indicates the common event that the Wi-Fi signal strength (RSSI) has changed. |
......
...@@ -40,7 +40,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re ...@@ -40,7 +40,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re
| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ | | -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
| context | [Context](js-apis-ability-context.md) | Yes | Application context. | | context | [Context](js-apis-ability-context.md) | Yes | Application context. |
| name | string | Yes | Name of the **Preferences** instance. | | name | string | Yes | Name of the **Preferences** instance. |
| callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;[Preferences](#preferences)&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is undefined and the **Preferences** instance obtained is returned. Otherwise, **err** is an error code.|
**Example** **Example**
...@@ -66,12 +66,14 @@ Obtains a **Preferences** instance. This API uses a promise to return the result ...@@ -66,12 +66,14 @@ Obtains a **Preferences** instance. This API uses a promise to return the result
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | -------------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | [Context](js-apis-ability-context.md) | Yes | Application context. | | context | [Context](js-apis-ability-context.md) | Yes | Application context. |
| name | string | Yes | Name of the **Preferences** instance.| | name | string | Yes | Name of the **Preferences** instance.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------------ | ---------------------------------- | | ------------------------------------------ | ---------------------------------- |
| Promise&lt;[Preferences](#preferences)&gt; | Promise used to return the **Preferences** instance obtained.| | Promise&lt;[Preferences](#preferences)&gt; | Promise used to return the **Preferences** instance obtained.|
...@@ -103,6 +105,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -103,6 +105,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
| context | [Context](js-apis-ability-context.md) | Yes | Application context. | | context | [Context](js-apis-ability-context.md) | Yes | Application context. |
...@@ -110,6 +113,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -110,6 +113,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
**Example** **Example**
```js ```js
data_preferences.deletePreferences(this.context, 'mystore', function (err) { data_preferences.deletePreferences(this.context, 'mystore', function (err) {
if (err) { if (err) {
...@@ -134,17 +138,20 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi ...@@ -134,17 +138,20 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | -------------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | [Context](js-apis-ability-context.md) | Yes | Application context. | | context | [Context](js-apis-ability-context.md) | Yes | Application context. |
| name | string | Yes | Name of the **Preferences** instance to delete.| | name | string | Yes | Name of the **Preferences** instance to delete.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let promise = data_preferences.deletePreferences(this.context, 'mystore') let promise = data_preferences.deletePreferences(this.context, 'mystore')
promise.then(() => { promise.then(() => {
...@@ -166,6 +173,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi ...@@ -166,6 +173,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
| context | [Context](js-apis-ability-context.md) | Yes | Application context. | | context | [Context](js-apis-ability-context.md) | Yes | Application context. |
...@@ -173,6 +181,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi ...@@ -173,6 +181,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
**Example** **Example**
```js ```js
data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err) { data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err) {
if (err) { if (err) {
...@@ -195,17 +204,20 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi ...@@ -195,17 +204,20 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | -------------------------- | | ------- | ------------------------------------- | ---- | ----------------------- |
| context | [Context](js-apis-ability-context.md) | Yes | Application context. | | context | [Context](js-apis-ability-context.md) | Yes | Application context. |
| name | string | Yes | Name of the **Preferences** instance to remove.| | name | string | Yes | Name of the **Preferences** instance to remove.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let promise = data_preferences.removePreferencesFromCache(this.context, 'mystore') let promise = data_preferences.removePreferencesFromCache(this.context, 'mystore')
promise.then(() => { promise.then(() => {
...@@ -232,6 +244,7 @@ Obtains the value of a key. This API uses an asynchronous callback to return the ...@@ -232,6 +244,7 @@ Obtains the value of a key. This API uses an asynchronous callback to return the
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data to obtain. It cannot be empty. | | key | string | Yes | Key of the data to obtain. It cannot be empty. |
...@@ -260,6 +273,7 @@ Obtains the value of a key. This API uses a promise to return the result. If the ...@@ -260,6 +273,7 @@ Obtains the value of a key. This API uses a promise to return the result. If the
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ----------------------- | ---- | ------------------------------------------------------------ | | -------- | ----------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data to obtain. It cannot be empty. | | key | string | Yes | Key of the data to obtain. It cannot be empty. |
...@@ -272,6 +286,7 @@ Obtains the value of a key. This API uses a promise to return the result. If the ...@@ -272,6 +286,7 @@ Obtains the value of a key. This API uses a promise to return the result. If the
| Promise<[ValueType](#valuetype)&gt; | Promise used to return the value obtained.| | Promise<[ValueType](#valuetype)&gt; | Promise used to return the value obtained.|
**Example** **Example**
```js ```js
let promise = preferences.get('startup', 'default'); let promise = preferences.get('startup', 'default');
promise.then((data) => { promise.then((data) => {
...@@ -290,6 +305,7 @@ Obtains an **Object** instance that contains all KV pairs. This API uses an asyn ...@@ -290,6 +305,7 @@ Obtains an **Object** instance that contains all KV pairs. This API uses an asyn
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------- | ---- | ------------------------------------------------------------ | | -------- | --------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;Object&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **value** is the **Object** instance obtained. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;Object&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **value** is the **Object** instance obtained. Otherwise, **err** is an error code.|
...@@ -318,11 +334,13 @@ Obtains an **Object** instance that contains all KV pairs. This API uses a promi ...@@ -318,11 +334,13 @@ Obtains an **Object** instance that contains all KV pairs. This API uses a promi
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| --------------------- | ------------------------------------------- | | --------------------- | ------------------------------------------- |
| Promise&lt;Object&gt; | Promise used to return the **Object** instance obtained.| | Promise&lt;Object&gt; | Promise used to return the **Object** instance obtained.|
**Example** **Example**
```js ```js
let promise = preferences.getAll(); let promise = preferences.getAll();
promise.then((value) => { promise.then((value) => {
...@@ -343,6 +361,7 @@ Writes data to this **Preferences** instance. This API uses an asynchronous call ...@@ -343,6 +361,7 @@ Writes data to this **Preferences** instance. This API uses an asynchronous call
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. | | key | string | Yes | Key of the data. It cannot be empty. |
...@@ -350,6 +369,7 @@ Writes data to this **Preferences** instance. This API uses an asynchronous call ...@@ -350,6 +369,7 @@ Writes data to this **Preferences** instance. This API uses an asynchronous call
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is undefined. Otherwise, **err** is an error code. | | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is undefined. Otherwise, **err** is an error code. |
**Example** **Example**
```js ```js
preferences.put('startup', 'auto', function (err) { preferences.put('startup', 'auto', function (err) {
if (err) { if (err) {
...@@ -370,17 +390,20 @@ Writes data to this **Preferences** instance. This API uses a promise to return ...@@ -370,17 +390,20 @@ Writes data to this **Preferences** instance. This API uses a promise to return
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ----------------------- | ---- | ------------------------------------------------------------ | | ------ | ----------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data. It cannot be empty. | | key | string | Yes | Key of the data. It cannot be empty. |
| value | [ValueType](#valuetype) | Yes | Value to write. The value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.| | value | [ValueType](#valuetype) | Yes | Value to write. The value can be a number, a string, a Boolean value, or an array of numbers, strings, or Boolean values.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let promise = preferences.put('startup', 'auto'); let promise = preferences.put('startup', 'auto');
promise.then(() => { promise.then(() => {
...@@ -400,12 +423,14 @@ Checks whether this **Preferences** instance contains a KV pair of the given key ...@@ -400,12 +423,14 @@ Checks whether this **Preferences** instance contains a KV pair of the given key
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ---------------------------- | ---- | ------------------------------------------------------------ | | -------- | ---------------------------- | ---- | ------------------------------------------------------------ |
| key | string | Yes | Key of the data to check. It cannot be empty. | | key | string | Yes | Key of the data to check. It cannot be empty. |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If the **Preferences** instance contains the KV pair, **true** will be returned. Otherwise, **false** will be returned.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback invoked to return the result. If the **Preferences** instance contains the KV pair, **true** will be returned. Otherwise, **false** will be returned.|
**Example** **Example**
```js ```js
preferences.has('startup', function (err, isExist) { preferences.has('startup', function (err, isExist) {
if (err) { if (err) {
...@@ -430,11 +455,13 @@ Checks whether this **Preferences** instance contains data with the given key. T ...@@ -430,11 +455,13 @@ Checks whether this **Preferences** instance contains data with the given key. T
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------- | | ------ | ------ | ---- | ------------------------------- |
| key | string | Yes | Key of the data to check. It cannot be empty.| | key | string | Yes | Key of the data to check. It cannot be empty.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------------------- | ------------------------------------------------------------ | | ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. If the **Preferences** instance contains the KV pair, **true** will be returned. Otherwise, **false** will be returned.| | Promise&lt;boolean&gt; | Promise used to return the result. If the **Preferences** instance contains the KV pair, **true** will be returned. Otherwise, **false** will be returned.|
...@@ -464,12 +491,14 @@ Deletes a KV pair from this **Preferences** instance. This API uses an asynchron ...@@ -464,12 +491,14 @@ Deletes a KV pair from this **Preferences** instance. This API uses an asynchron
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------------------- |
| key | string | Yes | Key of the KV pair to delete. It cannot be empty. | | key | string | Yes | Key of the KV pair to delete. It cannot be empty. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
**Example** **Example**
```js ```js
preferences.delete('startup', function (err) { preferences.delete('startup', function (err) {
if (err) { if (err) {
...@@ -490,16 +519,19 @@ Deletes a KV pair from this **Preferences** instance. This API uses a promise to ...@@ -490,16 +519,19 @@ Deletes a KV pair from this **Preferences** instance. This API uses a promise to
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type | Mandatory| Description |
| ------ | ------ | ---- | ------------------------------- | | ------ | ------ | ---- | ------------------------------- |
| key | string | Yes | Key of the KV pair to delete. It cannot be empty.| | key | string | Yes | Key of the KV pair to delete. It cannot be empty.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let promise = preferences.delete('startup'); let promise = preferences.delete('startup');
promise.then(() => { promise.then(() => {
...@@ -514,16 +546,18 @@ promise.then(() => { ...@@ -514,16 +546,18 @@ promise.then(() => {
flush(callback: AsyncCallback&lt;void&gt;): void flush(callback: AsyncCallback&lt;void&gt;): void
Saves the data of the **Preferences** instance to a file asynchronously. This API uses an asynchronous callback to return the result. Asynchronously stores data of this **Preferences** instance to its persistent file. This API uses a asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
**Example** **Example**
```js ```js
preferences.flush(function (err) { preferences.flush(function (err) {
if (err) { if (err) {
...@@ -539,16 +573,18 @@ preferences.flush(function (err) { ...@@ -539,16 +573,18 @@ preferences.flush(function (err) {
flush(): Promise&lt;void&gt; flush(): Promise&lt;void&gt;
Saves the data of the **Preferences** instance to a file asynchronously. This API uses a promise to return the result. Asynchronously stores data of this **Preferences** instance to its persistent file. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let promise = preferences.flush(); let promise = preferences.flush();
promise.then(() => { promise.then(() => {
...@@ -568,11 +604,13 @@ Clears this **Preferences** instance. This API uses an asynchronous callback to ...@@ -568,11 +604,13 @@ Clears this **Preferences** instance. This API uses an asynchronous callback to
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------------------------------------------------- | | -------- | ------------------------- | ---- | ---------------------------------------------------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.| | callback | AsyncCallback&lt;void&gt; | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
**Example** **Example**
```js ```js
preferences.clear(function (err) { preferences.clear(function (err) {
if (err) { if (err) {
...@@ -593,11 +631,13 @@ Clears this **Preferences** instance. This API uses a promise to return the resu ...@@ -593,11 +631,13 @@ Clears this **Preferences** instance. This API uses a promise to return the resu
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------- | ------------------------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise that returns no value.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
let promise = preferences.clear() let promise = preferences.clear()
promise.then(() => { promise.then(() => {
...@@ -617,56 +657,14 @@ Subscribes to data changes. A callback will be triggered to return the new value ...@@ -617,56 +657,14 @@ Subscribes to data changes. A callback will be triggered to return the new value
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core **System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ---------------------------------------- | | -------- | -------------------------------- | ---- | ---------------------------------------- |
| type | string | Yes | Event type to subscribe to. The value **change** indicates data change events.| | type | string | Yes | Event type to subscribe to. The value **change** indicates data change events.|
| callback | Callback&lt;{ key : string }&gt; | Yes | Callback invoked to return data changes. | | callback | Callback&lt;{ key : string }&gt; | Yes | Callback invoked to return data changes. |
**Example** **Example**
```js
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) {
console.info("Failed to get the preferences.");
return;
}
var observer = function (key) {
console.info("The key " + key + " changed.");
}
preferences.on('change', observer);
preferences.put('startup', 'auto', function (err) {
if (err) {
console.info("Failed to put the value of 'startup'. Cause: " + err);
return;
}
console.info("Put the value of 'startup' successfully.");
preferences.flush(function (err) {
if (err) {
console.info("Failed to flush data. Cause: " + err);
return;
}
console.info("Flushed data successfully."); // The observer will be called.
})
})
})
```
### off('change')
off(type: 'change', callback?: Callback&lt;{ key : string }&gt;): void
Unsubscribes from data changes.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type to unsubscribe from. The value **change** indicates data change events. |
| callback | Callback&lt;{ key : string }&gt; | No | Callback to unregister. If this parameter is left blank, the callbacks used to subscribing to all data changes will be unregistered.|
**Example**
```js ```js
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) { if (err) {
......
...@@ -40,9 +40,11 @@ Creates a **PixelMap** object with the default BGRA_8888 format and pixel proper ...@@ -40,9 +40,11 @@ Creates a **PixelMap** object with the default BGRA_8888 format and pixel proper
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
let bufferArr = new Uint8Array(color); let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } } let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts) image.createPixelMap(color, opts).then((pixelmap) => {
.then((pixelmap) => { console.log('Succeeded in creating pixelmap.');
}) }).catch(error => {
console.log('Failed to create pixelmap.');
})
``` ```
## image.createPixelMap<sup>8+</sup> ## image.createPixelMap<sup>8+</sup>
...@@ -115,7 +117,7 @@ const readBuffer = new ArrayBuffer(96); ...@@ -115,7 +117,7 @@ const readBuffer = new ArrayBuffer(96);
pixelmap.readPixelsToBuffer(readBuffer).then(() => { pixelmap.readPixelsToBuffer(readBuffer).then(() => {
console.log('Succeeded in reading image pixel data.'); // Called if the condition is met. console.log('Succeeded in reading image pixel data.'); // Called if the condition is met.
}).catch(error => { }).catch(error => {
('Failed to read image pixel data.'); // Called if no condition is met. console.log('Failed to read image pixel data.'); // Called if no condition is met.
}) })
``` ```
...@@ -261,12 +263,7 @@ image.createPixelMap(color, opts) ...@@ -261,12 +263,7 @@ image.createPixelMap(color, opts)
} }
pixelmap.writePixels(area).then(() => { pixelmap.writePixels(area).then(() => {
const readArea = { pixels: new ArrayBuffer(8), console.info('Succeeded to write pixelmap into the specified area.');
offset: 0,
stride: 8,
// region.size.width + x < opts.width, region.size.height + y < opts.height
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
}) })
}).catch(error => { }).catch(error => {
console.log('error: ' + error); console.log('error: ' + error);
...@@ -291,17 +288,20 @@ Writes image pixel map data to an area. This API uses an asynchronous callback t ...@@ -291,17 +288,20 @@ Writes image pixel map data to an area. This API uses an asynchronous callback t
**Example** **Example**
```js ```js
const area = new ArrayBuffer(400); const area = { pixels: new ArrayBuffer(8),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 }
}
let bufferArr = new Uint8Array(area.pixels);
for (var i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1;
}
pixelmap.writePixels(area, (error) => { pixelmap.writePixels(area, (error) => {
if (error != undefined) { if (error != undefined) {
console.info('Failed to write pixelmap into the specified area.'); console.info('Failed to write pixelmap into the specified area.');
} else { } else {
const readArea = { console.info('Succeeded to write pixelmap into the specified area.');
pixels: new ArrayBuffer(20),
offset: 0,
stride: 8,
region: { size: { height: 1, width: 2 }, x: 0, y: 0 },
}
} }
}) })
``` ```
...@@ -330,9 +330,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj ...@@ -330,9 +330,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
const pixelMap = new ArrayBuffer(400);
let bufferArr = new Uint8Array(color); let bufferArr = new Uint8Array(color);
pixelMap.writeBufferToPixels(color).then(() => { for (var i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1;
}
pixelmap.writeBufferToPixels(color).then(() => {
console.log("Succeeded in writing data from a buffer to a PixelMap."); console.log("Succeeded in writing data from a buffer to a PixelMap.");
}).catch((err) => { }).catch((err) => {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
...@@ -358,9 +360,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj ...@@ -358,9 +360,11 @@ Reads image data in an **ArrayBuffer** and writes the data to a **PixelMap** obj
```js ```js
const color = new ArrayBuffer(96); const color = new ArrayBuffer(96);
const pixelMap = new ArrayBuffer(400);
let bufferArr = new Uint8Array(color); let bufferArr = new Uint8Array(color);
pixelMap.writeBufferToPixels(color, function(err) { for (var i = 0; i < bufferArr.length; i++) {
bufferArr[i] = i + 1;
}
pixelmap.writeBufferToPixels(color, function(err) {
if (err) { if (err) {
console.error("Failed to write data from a buffer to a PixelMap."); console.error("Failed to write data from a buffer to a PixelMap.");
return; return;
...@@ -387,12 +391,21 @@ Obtains pixel map information of this image. This API uses a promise to return t ...@@ -387,12 +391,21 @@ Obtains pixel map information of this image. This API uses a promise to return t
**Example** **Example**
```js ```js
const pixelMap = new ArrayBuffer(400); const color = new ArrayBuffer(96);
pixelMap.getImageInfo().then(function(info) { let opts = { editable: true, pixelFormat: 2, size: { height: 6, width: 8 } }
console.log("Succeeded in obtaining the image pixel map information."); image.createPixelMap(color, opts).then(pixelmap => {
}).catch((err) => { if (pixelmap == undefined) {
console.error("Failed to obtain the image pixel map information."); console.error("Failed to obtain the image pixel map information.");
}); }
pixelmap.getImageInfo().then(imageInfo => {
if (imageInfo == undefined) {
console.error("Failed to obtain the image pixel map information.");
}
if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
console.log("Succeeded in obtaining the image pixel map information.");
}
})
})
``` ```
### getImageInfo<sup>7+</sup> ### getImageInfo<sup>7+</sup>
...@@ -412,8 +425,20 @@ Obtains pixel map information of this image. This API uses an asynchronous callb ...@@ -412,8 +425,20 @@ Obtains pixel map information of this image. This API uses an asynchronous callb
**Example** **Example**
```js ```js
pixelmap.getImageInfo((imageInfo) => { const color = new ArrayBuffer(96);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (err, pixelmap) => {
if (pixelmap == undefined) {
console.error("Failed to obtain the image pixel map information.");
}
pixelmap.getImageInfo((err, imageInfo) => {
if (imageInfo == undefined) {
console.error("Failed to obtain the image pixel map information.");
}
if (imageInfo.size.height == 4 && imageInfo.size.width == 6) {
console.log("Succeeded in obtaining the image pixel map information."); console.log("Succeeded in obtaining the image pixel map information.");
}
})
}) })
``` ```
...@@ -500,9 +525,15 @@ Sets an opacity rate for this image pixel map. This API uses an asynchronous cal ...@@ -500,9 +525,15 @@ Sets an opacity rate for this image pixel map. This API uses an asynchronous cal
**Example** **Example**
```js ```js
async function () { var rate = 0.5;
await pixelMap.opacity(0.5); pixelmap.opacity(rate, (err) => {
} if (err) {
console.error("Failed to set opacity.");
return;
} else {
console.log("Succeeded in setting opacity.");
}
})
``` ```
### opacity<sup>9+</sup> ### opacity<sup>9+</sup>
...@@ -528,8 +559,8 @@ Sets an opacity rate for this image pixel map. This API uses a promise to return ...@@ -528,8 +559,8 @@ Sets an opacity rate for this image pixel map. This API uses a promise to return
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.opacity(0.5); await pixelmap.opacity(0.5);
} }
``` ```
...@@ -550,13 +581,9 @@ Creates a **PixelMap** object that contains only the alpha channel information. ...@@ -550,13 +581,9 @@ Creates a **PixelMap** object that contains only the alpha channel information.
**Example** **Example**
```js ```js
pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => { async function Demo() {
if (alphaPixelMap == undefined) { await pixelmap.createAlphaPixelmap();
console.info('Failed to obtain new pixel map.'); }
} else {
console.info('Succeed in obtaining new pixel map.');
}
})
``` ```
### createAlphaPixelmap<sup>9+</sup> ### createAlphaPixelmap<sup>9+</sup>
...@@ -576,14 +603,13 @@ Creates a **PixelMap** object that contains only the alpha channel information. ...@@ -576,14 +603,13 @@ Creates a **PixelMap** object that contains only the alpha channel information.
**Example** **Example**
```js ```js
let pixelMap = await imageSource.createPixelMap(); pixelmap.createAlphaPixelmap((err, alphaPixelMap) => {
if (pixelMap != undefined) { if (alphaPixelMap == undefined) {
pixelMap.createAlphaPixelmap(async (err, alphaPixelMap) => {
console.info('Failed to obtain new pixel map.'); console.info('Failed to obtain new pixel map.');
}) } else {
} else {
console.info('Succeed in obtaining new pixel map.'); console.info('Succeed in obtaining new pixel map.');
} }
})
``` ```
### scale<sup>9+</sup> ### scale<sup>9+</sup>
...@@ -605,8 +631,8 @@ Scales this image based on the input width and height. This API uses an asynchro ...@@ -605,8 +631,8 @@ Scales this image based on the input width and height. This API uses an asynchro
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.scale(2.0, 1.0); await pixelmap.scale(2.0, 1.0);
} }
``` ```
...@@ -634,8 +660,8 @@ Scales this image based on the input width and height. This API uses a promise t ...@@ -634,8 +660,8 @@ Scales this image based on the input width and height. This API uses a promise t
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.scale(2.0, 1.0); await pixelmap.scale(2.0, 1.0);
} }
``` ```
...@@ -658,8 +684,8 @@ Translates this image based on the input coordinates. This API uses an asynchron ...@@ -658,8 +684,8 @@ Translates this image based on the input coordinates. This API uses an asynchron
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.translate(3.0, 1.0); await pixelmap.translate(3.0, 1.0);
} }
``` ```
...@@ -687,8 +713,8 @@ Translates this image based on the input coordinates. This API uses a promise to ...@@ -687,8 +713,8 @@ Translates this image based on the input coordinates. This API uses a promise to
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.translate(3.0, 1.0); await pixelmap.translate(3.0, 1.0);
} }
``` ```
...@@ -710,8 +736,8 @@ Rotates this image based on the input angle. This API uses an asynchronous callb ...@@ -710,8 +736,8 @@ Rotates this image based on the input angle. This API uses an asynchronous callb
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.rotate(90.0); await pixelmap.rotate(90.0);
} }
``` ```
...@@ -738,8 +764,8 @@ Rotates this image based on the input angle. This API uses a promise to return t ...@@ -738,8 +764,8 @@ Rotates this image based on the input angle. This API uses a promise to return t
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.rotate(90.0); await pixelmap.rotate(90.0);
} }
``` ```
...@@ -762,8 +788,8 @@ Flips this image horizontally or vertically, or both. This API uses an asynchron ...@@ -762,8 +788,8 @@ Flips this image horizontally or vertically, or both. This API uses an asynchron
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.flip(false, true); await pixelmap.flip(false, true);
} }
``` ```
...@@ -791,8 +817,8 @@ Flips this image horizontally or vertically, or both. This API uses a promise to ...@@ -791,8 +817,8 @@ Flips this image horizontally or vertically, or both. This API uses a promise to
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.flip(false, true); await pixelmap.flip(false, true);
} }
``` ```
...@@ -814,8 +840,8 @@ Crops this image based on the input size. This API uses an asynchronous callback ...@@ -814,8 +840,8 @@ Crops this image based on the input size. This API uses an asynchronous callback
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } }); await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
} }
``` ```
...@@ -842,8 +868,8 @@ Crops this image based on the input size. This API uses a promise to return the ...@@ -842,8 +868,8 @@ Crops this image based on the input size. This API uses a promise to return the
**Example** **Example**
```js ```js
async function () { async function Demo() {
await pixelMap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } }); await pixelmap.crop({ x: 0, y: 0, size: { height: 100, width: 100 } });
} }
``` ```
...@@ -864,15 +890,10 @@ Releases this **PixelMap** object. This API uses a promise to return the result. ...@@ -864,15 +890,10 @@ Releases this **PixelMap** object. This API uses a promise to return the result.
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96); pixelmap.release().then(() => {
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (pixelmap) => {
pixelmap.release().then(() => {
console.log('Succeeded in releasing pixelmap object.'); console.log('Succeeded in releasing pixelmap object.');
}).catch(error => { }).catch(error => {
console.log('Failed to release pixelmap object.'); console.log('Failed to release pixelmap object.');
})
}) })
``` ```
...@@ -893,13 +914,8 @@ Releases this **PixelMap** object. This API uses an asynchronous callback to ret ...@@ -893,13 +914,8 @@ Releases this **PixelMap** object. This API uses an asynchronous callback to ret
**Example** **Example**
```js ```js
const color = new ArrayBuffer(96); pixelmap.release(() => {
let bufferArr = new Uint8Array(color);
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts, (pixelmap) => {
pixelmap.release().then(() => {
console.log('Succeeded in releasing pixelmap object.'); console.log('Succeeded in releasing pixelmap object.');
})
}) })
``` ```
...@@ -954,7 +970,8 @@ Creates an **ImageSource** instance based on the URI. ...@@ -954,7 +970,8 @@ Creates an **ImageSource** instance based on the URI.
**Example** **Example**
```js ```js
const imageSourceApi = image.createImageSource('/sdcard/test.jpg'); var sourceOptions = { sourceDensity: 120 };
let imageSource = image.createImageSource('test.png', sourceOptions);
``` ```
## image.createImageSource<sup>7+</sup> ## image.createImageSource<sup>7+</sup>
...@@ -1007,7 +1024,8 @@ Creates an **ImageSource** instance based on the file descriptor. ...@@ -1007,7 +1024,8 @@ Creates an **ImageSource** instance based on the file descriptor.
**Example** **Example**
```js ```js
const imageSourceApi = image.createImageSource(fd); var sourceOptions = { sourceDensity: 120 };
const imageSourceApi = image.createImageSource(0, sourceOptions);
``` ```
## image.createImageSource<sup>9+</sup> ## image.createImageSource<sup>9+</sup>
...@@ -1059,9 +1077,9 @@ const data = new ArrayBuffer(112); ...@@ -1059,9 +1077,9 @@ const data = new ArrayBuffer(112);
const imageSourceApi = image.createImageSource(data); const imageSourceApi = image.createImageSource(data);
``` ```
## image.CreateIncrementalSource<sup>9+</sup> ## image.createIncrementalSource<sup>9+</sup>
CreateIncrementalSource(buf: ArrayBuffer): ImageSource createIncrementalSource(buf: ArrayBuffer): ImageSource
Creates an **ImageSource** instance in incremental mode based on the buffers. Creates an **ImageSource** instance in incremental mode based on the buffers.
...@@ -1083,12 +1101,12 @@ Creates an **ImageSource** instance in incremental mode based on the buffers. ...@@ -1083,12 +1101,12 @@ Creates an **ImageSource** instance in incremental mode based on the buffers.
```js ```js
const buf = new ArrayBuffer(96); const buf = new ArrayBuffer(96);
const imageSourceApi = image.CreateIncrementalSource(buf); const imageSourceIncrementalSApi = image.createIncrementalSource(buf);
``` ```
## image.CreateIncrementalSource<sup>9+</sup> ## image.createIncrementalSource<sup>9+</sup>
CreateIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource createIncrementalSource(buf: ArrayBuffer, options?: SourceOptions): ImageSource
Creates an **ImageSource** instance in incremental mode based on the buffers. Creates an **ImageSource** instance in incremental mode based on the buffers.
...@@ -1111,7 +1129,7 @@ Creates an **ImageSource** instance in incremental mode based on the buffers. ...@@ -1111,7 +1129,7 @@ Creates an **ImageSource** instance in incremental mode based on the buffers.
```js ```js
const buf = new ArrayBuffer(96); const buf = new ArrayBuffer(96);
const imageSourceApi = image.CreateIncrementalSource(buf); const imageSourceIncrementalSApi = image.createIncrementalSource(buf);
``` ```
## ImageSource ## ImageSource
...@@ -1124,7 +1142,7 @@ Provides APIs to obtain image information. Before calling any API in **ImageSour ...@@ -1124,7 +1142,7 @@ Provides APIs to obtain image information. Before calling any API in **ImageSour
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ | | ---------------- | -------------- | ---- | ---- | ------------------------------------------------------------ |
| supportedFormats | Array\<string> | Yes | No | Supported image formats, including png, jpeg, wbmp, bmp, gif, webp, and heif.| | supportedFormats | Array\<string> | Yes | No | Supported image formats, including PNG, JPEG, BMP, GIF, WebP, and RAW.|
### getImageInfo ### getImageInfo
...@@ -1282,7 +1300,7 @@ Obtains the value of a property in this image. This API uses an asynchronous cal ...@@ -1282,7 +1300,7 @@ Obtains the value of a property in this image. This API uses an asynchronous cal
**Example** **Example**
```js ```js
const property = new ArrayBuffer(400); let property = { index: 0, defaultValue: '9999' }
imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => { imageSourceApi.getImageProperty("BitsPerSample",property,(error,data) => {
if(error) { if(error) {
console.log('Failed to get the value of the specified attribute key of the image.'); console.log('Failed to get the value of the specified attribute key of the image.');
...@@ -1316,11 +1334,10 @@ Modifies the value of a property in this image. This API uses a promise to retur ...@@ -1316,11 +1334,10 @@ Modifies the value of a property in this image. This API uses a promise to retur
**Example** **Example**
```js ```js
imageSourceApi.modifyImageProperty("ImageWidth", "120") imageSourceApi.modifyImageProperty("ImageWidth", "120").then(() => {
.then(() => {
const w = imageSourceApi.getImageProperty("ImageWidth") const w = imageSourceApi.getImageProperty("ImageWidth")
console.info('w', w); console.info('w', w);
}) })
``` ```
### modifyImageProperty<sup>9+</sup> ### modifyImageProperty<sup>9+</sup>
...@@ -1372,9 +1389,9 @@ Updates incremental data. This API uses a promise to return the result. ...@@ -1372,9 +1389,9 @@ Updates incremental data. This API uses a promise to return the result.
```js ```js
const array = new ArrayBuffer(100); const array = new ArrayBuffer(100);
imageSourceIncrementalSApi.updateData(array, false, 0, 10).then(data => { imageSourceApi.updateData(array, false, 0, 10).then(data => {
console.info('Succeeded in updating data.'); console.info('Succeeded in updating data.');
}) })
``` ```
...@@ -1400,11 +1417,11 @@ Updates incremental data. This API uses an asynchronous callback to return the r ...@@ -1400,11 +1417,11 @@ Updates incremental data. This API uses an asynchronous callback to return the r
```js ```js
const array = new ArrayBuffer(100); const array = new ArrayBuffer(100);
imageSourceIncrementalSApi.updateData(array, false, 0, 10,(error,data )=> { imageSourceApi.updateData(array, false, 0, 10,(error,data )=> {
if(data !== undefined){ if(data !== undefined){
console.info('Succeeded in updating data.'); console.info('Succeeded in updating data.');
} }
}) })
``` ```
### createPixelMap<sup>7+</sup> ### createPixelMap<sup>7+</sup>
...@@ -1477,7 +1494,15 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses ...@@ -1477,7 +1494,15 @@ Creates a **PixelMap** object based on image decoding parameters. This API uses
**Example** **Example**
```js ```js
const decodingOptions = new ArrayBuffer(400); let decodingOptions = {
sampleSize: 1,
editable: true,
desiredSize: { width: 1, height: 2 },
rotate: 10,
desiredPixelFormat: 3,
desiredRegion: { size: { height: 1, width: 2 }, x: 0, y: 0 },
index: 0
};
imageSourceApi.createPixelMap(decodingOptions, pixelmap => { imageSourceApi.createPixelMap(decodingOptions, pixelmap => {
console.log('Succeeded in creating pixelmap object.'); console.log('Succeeded in creating pixelmap object.');
}) })
...@@ -1551,7 +1576,7 @@ const imagePackerApi = image.createImagePacker(); ...@@ -1551,7 +1576,7 @@ const imagePackerApi = image.createImagePacker();
## ImagePacker ## ImagePacker
Provide APIs to pack images. Before calling any API in **ImagePacker**, you must use **createImagePacker** to create an **ImagePacker** instance. Provides APIs to pack images. Before calling any API in **ImagePacker**, you must use **createImagePacker** to create an **ImagePacker** instance. The image formats JPEG and WebP are supported.
### Attributes ### Attributes
...@@ -1580,8 +1605,8 @@ Packs an image. This API uses an asynchronous callback to return the result. ...@@ -1580,8 +1605,8 @@ Packs an image. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
const imageSourceApi = image.createImageSource(0);
let packOpts = { format:"image/jpeg", quality:98 }; let packOpts = { format:"image/jpeg", quality:98 };
const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts, data => {}) imagePackerApi.packing(imageSourceApi, packOpts, data => {})
``` ```
...@@ -1610,7 +1635,6 @@ Packs an image. This API uses a promise to return the result. ...@@ -1610,7 +1635,6 @@ Packs an image. This API uses a promise to return the result.
```js ```js
let packOpts = { format:"image/jpeg", quality:98 } let packOpts = { format:"image/jpeg", quality:98 }
const imageSourceApi = new ArrayBuffer(400);
imagePackerApi.packing(imageSourceApi, packOpts) imagePackerApi.packing(imageSourceApi, packOpts)
.then( data => { .then( data => {
console.log('packing succeeded.'); console.log('packing succeeded.');
...@@ -1638,10 +1662,14 @@ Packs an image. This API uses an asynchronous callback to return the result. ...@@ -1638,10 +1662,14 @@ Packs an image. This API uses an asynchronous callback to return the result.
**Example** **Example**
```js ```js
let packOpts = { format:"image/jpeg", quality:98 } const color = new ArrayBuffer(96);
const pixelMapApi = new ArrayBuffer(400); let bufferArr = new Uint8Array(color);
imagePackerApi.packing(pixelMapApi, packOpts, data => { let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelmap) => {
let packOpts = { format:"image/jpeg", quality:98 }
imagePackerApi.packing(pixelMapApi, packOpts, data => {
console.log('Succeeded in packing the image.'); console.log('Succeeded in packing the image.');
})
}) })
``` ```
...@@ -1669,14 +1697,18 @@ Packs an image. This API uses a promise to return the result. ...@@ -1669,14 +1697,18 @@ Packs an image. This API uses a promise to return the result.
**Example** **Example**
```js ```js
let packOpts = { format:"image/jpeg", quality:98 } const color = new ArrayBuffer(96);
const pixelMapApi = new ArrayBuffer(400); let bufferArr = new Uint8Array(color);
imagePackerApi.packing(pixelMapApi, packOpts) let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
image.createPixelMap(color, opts).then((pixelmap) => {
let packOpts = { format:"image/jpeg", quality:98 }
imagePackerApi.packing(pixelMapApi, packOpts)
.then( data => { .then( data => {
console.log('Succeeded in packing the image.'); console.log('Succeeded in packing the image.');
}).catch(error => { }).catch(error => {
console.log('Failed to pack the image..'); console.log('Failed to pack the image..');
}) })
})
``` ```
### release ### release
...@@ -2146,8 +2178,8 @@ Enumerates the pixel formats of images. ...@@ -2146,8 +2178,8 @@ Enumerates the pixel formats of images.
| ---------------------- | ------ | ----------------- | | ---------------------- | ------ | ----------------- |
| UNKNOWN | 0 | Unknown format. | | UNKNOWN | 0 | Unknown format. |
| RGB_565 | 2 | RGB_565. | | RGB_565 | 2 | RGB_565. |
| RGBA_8888 | 3 | RGBA_8888.| | RGBA_8888 | 3 | RGBA_8888. |
| BGRA_8888<sup>9+</sup> | 4 | BGRA_8888.| | BGRA_8888<sup>9+</sup> | 4 | BGRA_8888. |
## AlphaType<sup>9+</sup> ## AlphaType<sup>9+</sup>
...@@ -2236,7 +2268,7 @@ Defines the option for image packing. ...@@ -2236,7 +2268,7 @@ Defines the option for image packing.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------- | ------ | ---- | ---- | --------------------------------------------------- | | ------- | ------ | ---- | ---- | --------------------------------------------------- |
| format | string | Yes | Yes | Format of the packed image.<br>Currently, the following raw formats are supported: .jpg, .png, .gif, .bmp, and .webp. | | format | string | Yes | Yes | Format of the packed image.<br>Currently, the JPEG and WebP formats are supported. |
| quality | number | Yes | Yes | Quality of the output image during JPEG encoding. The value ranges from 1 to 100.| | quality | number | Yes | Yes | Quality of the output image during JPEG encoding. The value ranges from 1 to 100.|
## GetImagePropertyOptions<sup>7+</sup> ## GetImagePropertyOptions<sup>7+</sup>
......
...@@ -164,8 +164,8 @@ Only one **AudioRecorder** instance can be created per device. ...@@ -164,8 +164,8 @@ Only one **AudioRecorder** instance can be created per device.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ----------------------------------------- | ----------------------------------- | | ----------------------------------------- | ------------------------------------------------------------ |
| Promise<[VideoRecorder](#videorecorder9)> | Promise used to return the **VideoRecorder** instance created.| | Promise<[VideoRecorder](#videorecorder9)> | Promise used to return the **VideoRecorder** instance created. |
**Example** **Example**
...@@ -276,8 +276,8 @@ For details about the audio playback demo, see [Audio Playback Development](../. ...@@ -276,8 +276,8 @@ For details about the audio playback demo, see [Audio Playback Development](../.
**System capability**: SystemCapability.Multimedia.Media.AudioPlayer **System capability**: SystemCapability.Multimedia.Media.AudioPlayer
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------------------- | ----------------------------------- | ---- | ---- | ------------------------------------------------------------ | | ------------------------------- | ------------------------------------------------------ | ---- | ---- | ------------------------------------------------------------ |
| src | string | Yes | Yes | Audio file URI. The mainstream audio formats (M4A, AAC, MPEG-3, OGG, and WAV) are supported.<br>**Examples of supported URI schemes**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http://xx<br>3. HTTPS: https://xx<br>4. HLS: http://xx or https://xx<br>**Required permissions**: ohos.permission.INTERNET| | src | string | Yes | Yes | Audio file URI. The mainstream audio formats (M4A, AAC, MPEG-3, OGG, and WAV) are supported.<br>**Examples of supported URI schemes**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http://xx<br>3. HTTPS: https://xx<br>4. HLS: http://xx or https://xx<br>**Required permissions**: ohos.permission.READ_MEDIA or ohos.permission.INTERNET|
| fdSrc<sup>9+</sup> | [AVFileDescriptor](#avfiledescriptor9) | Yes | Yes | Description of the audio file. This attribute is required when audio resources of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music resources consists of the following:<br>Music 1 (address offset: 0, byte length: 100)<br>Music 2 (address offset: 101; byte length: 50)<br>Music 3 (address offset: 151, byte length: 150)<br>1. To play music 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play music 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play music 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>If the file is an independent music file, use **src=fd://xx**.<br>| | fdSrc<sup>9+</sup> | [AVFileDescriptor](#avfiledescriptor9) | Yes | Yes | Description of the audio file. This attribute is required when audio resources of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music resources consists of the following:<br>Music 1 (address offset: 0, byte length: 100)<br>Music 2 (address offset: 101; byte length: 50)<br>Music 3 (address offset: 151, byte length: 150)<br>1. To play music 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play music 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play music 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>If the file is an independent music file, use **src=fd://xx**.<br>|
| loop | boolean | Yes | Yes | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite. | | loop | boolean | Yes | Yes | Whether to loop audio playback. The value **true** means to loop audio playback, and **false** means the opposite. |
| audioInterruptMode<sup>9+</sup> | [audio.InterruptMode](js-apis-audio.md#interruptmode9) | Yes | Yes | Audio interruption mode. | | audioInterruptMode<sup>9+</sup> | [audio.InterruptMode](js-apis-audio.md#interruptmode9) | Yes | Yes | Audio interruption mode. |
...@@ -442,7 +442,7 @@ function printfDescription(obj) { ...@@ -442,7 +442,7 @@ function printfDescription(obj) {
} }
} }
audioPlayer.getTrackDescription((error, ) => { audioPlayer.getTrackDescription((error, arrlist) => {
if (arrlist != null) { if (arrlist != null) {
for (let i = 0; i < arrlist.length; i++) { for (let i = 0; i < arrlist.length; i++) {
printfDescription(arrlist[i]); printfDescription(arrlist[i]);
...@@ -680,7 +680,7 @@ For details about the video playback demo, see [Video Playback Development](../. ...@@ -680,7 +680,7 @@ For details about the video playback demo, see [Video Playback Development](../.
| Name | Type | Readable| Writable| Description | | Name | Type | Readable| Writable| Description |
| ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ | | ------------------------ | ---------------------------------- | ---- | ---- | ------------------------------------------------------------ |
| url<sup>8+</sup> | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.<br>**Example of supported URIs**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http://xx<br>3. HTTPS: https://xx<br>4. HLS: http://xx or https://xx<br>**Required permissions**: ohos.permission.INTERNET| | url<sup>8+</sup> | string | Yes | Yes | Video media URL. The mainstream video formats (MPEG-4, MPEG-TS, WebM, and MKV) are supported.<br>**Example of supported URIs**:<br>1. FD: fd://xx<br>![](figures/en-us_image_url.png)<br>2. HTTP: http://xx<br>3. HTTPS: https://xx<br>4. HLS: http://xx or https://xx<br>|
| fdSrc<sup>9+</sup> | [AVFileDescriptor](#avfiledescriptor9) | Yes| Yes| Description of a video file. This attribute is required when video resources of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music resources consists of the following:<br>Video 1 (address offset: 0, byte length: 100)<br>Video 2 (address offset: 101; byte length: 50)<br>Video 3 (address offset: 151, byte length: 150)<br>1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>To play an independent video file, use **src=fd://xx**.<br>| | fdSrc<sup>9+</sup> | [AVFileDescriptor](#avfiledescriptor9) | Yes| Yes| Description of a video file. This attribute is required when video resources of an application are continuously stored in a file.<br>**Example:**<br>Assume that a music file that stores continuous music resources consists of the following:<br>Video 1 (address offset: 0, byte length: 100)<br>Video 2 (address offset: 101; byte length: 50)<br>Video 3 (address offset: 151, byte length: 150)<br>1. To play video 1: AVFileDescriptor {fd = resource handle; offset = 0; length = 100; }<br>2. To play video 2: AVFileDescriptor {fd = resource handle; offset = 101; length = 50; }<br>3. To play video 3: AVFileDescriptor {fd = resource handle; offset = 151; length = 150; }<br>To play an independent video file, use **src=fd://xx**.<br>|
| loop<sup>8+</sup> | boolean | Yes | Yes | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite. | | loop<sup>8+</sup> | boolean | Yes | Yes | Whether to loop video playback. The value **true** means to loop video playback, and **false** means the opposite. |
| videoScaleType<sup>9+</sup> | [VideoScaleType](#videoscaletype9) | Yes | Yes | Video scale type. | | videoScaleType<sup>9+</sup> | [VideoScaleType](#videoscaletype9) | Yes | Yes | Video scale type. |
...@@ -1795,7 +1795,7 @@ Subscribes to the audio recording events. ...@@ -1795,7 +1795,7 @@ Subscribes to the audio recording events.
```js ```js
let audioRecorder = media.createAudioRecorder(); // Create an AudioRecorder instance. let audioRecorder = media.createAudioRecorder(); // Create an AudioRecorder instance.
let audioRecorderConfig = { let audioRecorderConfig = {
audioEncoder : media.AudioEncoder.AAC_LC, , audioEncoder : media.AudioEncoder.AAC_LC,
audioEncodeBitRate : 22050, audioEncodeBitRate : 22050,
audioSampleRate : 22050, audioSampleRate : 22050,
numberOfChannels : 2, numberOfChannels : 2,
...@@ -1850,7 +1850,7 @@ Subscribes to audio recording error events. After an error event is reported, yo ...@@ -1850,7 +1850,7 @@ Subscribes to audio recording error events. After an error event is reported, yo
```js ```js
let audioRecorderConfig = { let audioRecorderConfig = {
audioEncoder : media.AudioEncoder.AAC_LC, , audioEncoder : media.AudioEncoder.AAC_LC,
audioEncodeBitRate : 22050, audioEncodeBitRate : 22050,
audioSampleRate : 22050, audioSampleRate : 22050,
numberOfChannels : 2, numberOfChannels : 2,
...@@ -1974,29 +1974,13 @@ let videoConfig = { ...@@ -1974,29 +1974,13 @@ let videoConfig = {
} }
// asyncallback // asyncallback
let videoRecorder = null; videoRecorder.prepare(videoConfig, (err) => {
let events = require('events');
let eventEmitter = new events.EventEmitter();
eventEmitter.on('prepare', () => {
videoRecorder.prepare(videoConfig, (err) => {
if (err == null) { if (err == null) {
console.info('prepare success'); console.info('prepare success');
} else { } else {
console.info('prepare failed and error is ' + err.message); console.info('prepare failed and error is ' + err.message);
} }
}); })
});
media.createVideoRecorder((err, recorder) => {
if (err == null && recorder != null) {
videoRecorder = recorder;
console.info('createVideoRecorder success');
eventEmitter.emit('prepare'); // Trigger the 'prepare' event.
} else {
console.info('createVideoRecorder failed and error is ' + err.message);
}
});
``` ```
### prepare<sup>9+</sup><a name=videorecorder_prepare2></a> ### prepare<sup>9+</sup><a name=videorecorder_prepare2></a>
...@@ -2047,21 +2031,10 @@ let videoConfig = { ...@@ -2047,21 +2031,10 @@ let videoConfig = {
} }
// promise // promise
let videoRecorder = null; videoRecorder.prepare(videoConfig).then(() => {
media.createVideoRecorder().then((recorder) => {
if (recorder != null) {
videoRecorder = recorder;
console.info('createVideoRecorder success');
videoRecorder.prepare(videoConfig).then(() => {
console.info('prepare success'); console.info('prepare success');
}).catch((err) => {
console.info('prepare failed and catch error is ' + err.message);
});
} else {
console.info('createVideoRecorder failed');
}
}).catch((err) => { }).catch((err) => {
console.info('catch err error message is ' + err.message); console.info('prepare failed and catch error is ' + err.message);
}); });
``` ```
...@@ -2475,11 +2448,10 @@ Subscribes to video recording error events. After an error event is reported, yo ...@@ -2475,11 +2448,10 @@ Subscribes to video recording error events. After an error event is reported, yo
**Example** **Example**
```js ```js
// This event is reported when an error occurs during the retrieval of videoRecordState.
videoRecorder.on('error', (error) => { // Set the 'error' event callback. videoRecorder.on('error', (error) => { // Set the 'error' event callback.
console.info(`audio error called, error: ${error}`); console.info(`audio error called, error: ${error}`);
} })
// This event is reported when an error occurs during the retrieval of videoRecordState.
});
``` ```
## VideoRecordState<sup>9+</sup> ## VideoRecordState<sup>9+</sup>
......
# ProcessRunningInfo # ProcessRunningInfo<sup>(deprecated)</sup>
The **ProcessRunningInfo** module provides process running information. The **ProcessRunningInfo** module provides process running information.
> **NOTE** > **NOTE**
> > - The APIs provided by this module are deprecated since API version 9. You are advised to use [ProcessRunningInformation<sup>9+</sup>](js-apis-processrunninginformation.md) instead.
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. > - The initial APIs of this module are supported since API version 8.
## Usage ## Usage
...@@ -19,9 +19,9 @@ appManager.getProcessRunningInfos((error,data) => { ...@@ -19,9 +19,9 @@ appManager.getProcessRunningInfos((error,data) => {
## Attributes ## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core **System capability**: SystemCapability.Ability.AbilityRuntime.Mission
| Name| Type| Readable| Writable| Description| | Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| pid | number | Yes| No| Process ID.| | pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.| | uid | number | Yes| No| User ID.|
......
# ProcessRunningInformation<sup>9+</sup>
The **ProcessRunningInformation** module provides process running information.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Usage Guidelines
The process running information is obtained through [appManager](js-apis-appmanager.md#appmanagergetprocessrunninginformation9).
```js
import appManager from '@ohos.application.appManager';
appManager.getProcessRunningInformation((error,data) => {
console.log("getProcessRunningInformation error: " + error.code + " data: " + JSON.stringify(data));
});
```
## Attributes
**System capability**: SystemCapability.Ability.AbilityRuntime.Core
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| pid | number | Yes| No| Process ID.|
| uid | number | Yes| No| User ID.|
| processName | string | Yes| No| Process name.|
| bundleNames | Array&lt;string&gt; | Yes| No| Names of all running bundles in the process.|
...@@ -1041,7 +1041,7 @@ promise1.then(() => { ...@@ -1041,7 +1041,7 @@ promise1.then(() => {
console.log('connect success'); console.log('connect success');
let promise2 = tcp.getRemoteAddress(); let promise2 = tcp.getRemoteAddress();
promise2.then(() => { promise2.then(() => {
console.log('getRemoteAddress success:' + JSON.stringify(data)); console.log('getRemoteAddress success');
}).catch(err => { }).catch(err => {
console.log('getRemoteAddressfail'); console.log('getRemoteAddressfail');
}); });
...@@ -1120,7 +1120,7 @@ promise.then(() => { ...@@ -1120,7 +1120,7 @@ promise.then(() => {
console.log('connect success'); console.log('connect success');
let promise1 = tcp.getState(); let promise1 = tcp.getState();
promise1.then(() => { promise1.then(() => {
console.log('getState success:' + JSON.stringify(data)); console.log('getState success');
}).catch(err => { }).catch(err => {
console.log('getState fail'); console.log('getState fail');
}); });
......
...@@ -22,8 +22,8 @@ import sensor from '@system.sensor'; ...@@ -22,8 +22,8 @@ import sensor from '@system.sensor';
## Error Codes ## Error Codes
| Error Code | Description | | Error Code | Description |
| ---- | -------------- | | ---------- | ---------------------------------------- |
| 900 | The current device does not support the corresponding sensor.| | 900 | The current device does not support the corresponding sensor. |
## sensor.subscribeAccelerometer ## sensor.subscribeAccelerometer
...@@ -38,18 +38,18 @@ Subscribes to data changes of the acceleration sensor. If this API is called mul ...@@ -38,18 +38,18 @@ Subscribes to data changes of the acceleration sensor. If this API is called mul
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | ---- | ---------------------------------------- | | -------- | -------- | --------- | ---------------------------------------- |
| interval | string | Yes | Execution frequency of the callback for returning the acceleration sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| | interval | string | Yes | Execution frequency of the callback for returning the acceleration sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios. |
| success | Function | Yes | Called when the acceleration sensor data changes. | | success | Function | Yes | Called when the acceleration sensor data changes. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| ---- | ------ | ------- | | ---- | ------ | --------------------------- |
| x | number | Acceleration on the x-axis.| | x | number | Acceleration on the x-axis. |
| y | number | Acceleration on the y-axis.| | y | number | Acceleration on the y-axis. |
| z | number | Acceleration on the z-axis.| | z | number | Acceleration on the z-axis. |
**Example** **Example**
...@@ -98,15 +98,15 @@ Subscribes to data changes of the compass sensor. If this API is called multiple ...@@ -98,15 +98,15 @@ Subscribes to data changes of the compass sensor. If this API is called multiple
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | -------- | ---- | --------------- | | ------- | -------- | --------- | ---------------------------------------- |
| success | Function | Yes | Called when the compass sensor data changes.| | success | Function | Yes | Called when the compass sensor data changes. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| --------- | ------ | ---------- | | --------- | ------ | ------------------------------------ |
| direction | number | Direction of the device, in degrees.| | direction | number | Direction of the device, in degrees. |
**Example** **Example**
...@@ -150,15 +150,15 @@ Subscribes to data changes of the proximity sensor. If this API is called multip ...@@ -150,15 +150,15 @@ Subscribes to data changes of the proximity sensor. If this API is called multip
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | -------- | ---- | ----------------- | | ------- | -------- | --------- | ---------------------------------------- |
| success | Function | Yes | Called when the proximity sensor data changes.| | success | Function | Yes | Called when the proximity sensor data changes. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| -------- | ------ | --------------------- | | -------- | ------ | ---------------------------------------- |
| distance | number | Distance between a visible object and the device screen.| | distance | number | Distance between a visible object and the device screen. |
**Example** **Example**
...@@ -202,15 +202,15 @@ Subscribes to data changes of the ambient light sensor. If this API is called mu ...@@ -202,15 +202,15 @@ Subscribes to data changes of the ambient light sensor. If this API is called mu
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | -------- | ---- | --------------- | | ------- | -------- | --------- | ---------------------------------------- |
| success | Function | Yes | Called when the ambient light sensor data changes| | success | Function | Yes | Called when the ambient light sensor data changes |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| --------- | ------ | ------------ | | --------- | ------ | ------------------------ |
| intensity | number | Light intensity, in lux.| | intensity | number | Light intensity, in lux. |
**Example** **Example**
...@@ -256,15 +256,15 @@ Subscribes to data changes of the step counter sensor. If this API is called mul ...@@ -256,15 +256,15 @@ Subscribes to data changes of the step counter sensor. If this API is called mul
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | -------- | ---- | ---------------- | | ------- | -------- | --------- | ---------------------------------------- |
| success | Function | Yes | Called when the step counter sensor data changes.| | success | Function | Yes | Called when the step counter sensor data changes. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| ----- | ------ | --------------------- | | ----- | ------ | ---------------------------------------- |
| steps | number | Number of counted steps after the sensor is restarted.<br>| | steps | number | Number of counted steps after the sensor is restarted.<br> |
**Example** **Example**
...@@ -302,7 +302,7 @@ sensor.unsubscribeStepCounter(); ...@@ -302,7 +302,7 @@ sensor.unsubscribeStepCounter();
## sensor.subscribeBarometer ## sensor.subscribeBarometer
subcribeBarometer(Object): void subscribeBarometer(Object): void
Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect. Subscribes to data changes of the barometer sensor. If this API is called multiple times for the same application, the last call takes effect.
...@@ -311,15 +311,15 @@ Subscribes to data changes of the barometer sensor. If this API is called multip ...@@ -311,15 +311,15 @@ Subscribes to data changes of the barometer sensor. If this API is called multip
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | -------- | ---- | ---------------- | | ------- | -------- | --------- | ---------------------------------------- |
| success | Function | Yes | Called when the barometer sensor data changes.| | success | Function | Yes | Called when the barometer sensor data changes. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| -------- | ------ | ----------- | | -------- | ------ | -------------------- |
| pressure | number | Pressure, in pascal.| | pressure | number | Pressure, in pascal. |
**Example** **Example**
...@@ -367,15 +367,15 @@ Subscribes to data changes of the heart rate sensor. If this API is called multi ...@@ -367,15 +367,15 @@ Subscribes to data changes of the heart rate sensor. If this API is called multi
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | -------- | ---- | ------------------------- | | ------- | -------- | --------- | ---------------------------------------- |
| success | Function | Yes | Called when the heart rate sensor data changes. This callback is invoked every five seconds.| | success | Function | Yes | Called when the heart rate sensor data changes. This callback is invoked every five seconds. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| --------- | ------ | ---- | | --------- | ------ | ----------- |
| heartRate | number | Heart rate.| | heartRate | number | Heart rate. |
**Example** **Example**
...@@ -422,15 +422,15 @@ Subscribes to changes of the wearing state of a wearable device. If this API is ...@@ -422,15 +422,15 @@ Subscribes to changes of the wearing state of a wearable device. If this API is
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------- | -------- | ---- | ------------- | | ------- | -------- | --------- | -------------------------------------- |
| success | Function | Yes | Called when the wearing state changes.| | success | Function | Yes | Called when the wearing state changes. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| ----- | ------- | ------ | | ----- | ------- | ------------------------------------ |
| value | boolean | Whether the wearable device is worn.| | value | boolean | Whether the wearable device is worn. |
**Example** **Example**
...@@ -474,16 +474,16 @@ Obtains the wearing state of a wearable device. ...@@ -474,16 +474,16 @@ Obtains the wearing state of a wearable device.
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | ---- | ------------ | | -------- | -------- | --------- | -------------------------------------- |
| success | Function | No | Callback upon success.| | success | Function | No | Callback upon success. |
| fail | Function | No | Callback upon failure.| | fail | Function | No | Callback upon failure. |
| complete | Function | No | Called when the execution is complete.| | complete | Function | No | Called when the execution is complete. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| ----- | ------- | ------ | | ----- | ------- | ------------------------------------ |
| value | boolean | Whether the wearable device is worn.| | value | boolean | Whether the wearable device is worn. |
**Example** **Example**
...@@ -511,17 +511,17 @@ If this API is called multiple times for the same application, the last call tak ...@@ -511,17 +511,17 @@ If this API is called multiple times for the same application, the last call tak
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | ---- | ---------------------------------------- | | -------- | -------- | --------- | ---------------------------------------- |
| interval | string | Yes | Interval at which the callback is invoked to return the device orientation sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| | interval | string | Yes | Interval at which the callback is invoked to return the device orientation sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios. |
| success | Function | Yes | Called when the device orientation sensor data changes. | | success | Function | Yes | Called when the device orientation sensor data changes. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| ----- | ------ | ---------------------------------------- | | ----- | ------ | ---------------------------------------- |
| alpha | number | Rotation angle around the Z axis when the X/Y axis of the device coincides with the X/Y axis of the earth.| | alpha | number | Rotation angle around the Z axis when the X/Y axis of the device coincides with the X/Y axis of the earth. |
| beta | number | Rotation angle around the X axis when the Y/Z axis of the device coincides with the Y/Z axis of the earth.| | beta | number | Rotation angle around the X axis when the Y/Z axis of the device coincides with the Y/Z axis of the earth. |
| gamma | number | Rotation angle around the Y axis when the X/Z axis of the device coincides with the X/Z axis of the earth.| | gamma | number | Rotation angle around the Y axis when the X/Z axis of the device coincides with the X/Z axis of the earth. |
**Example** **Example**
...@@ -572,18 +572,18 @@ If this API is called multiple times for the same application, the last call tak ...@@ -572,18 +572,18 @@ If this API is called multiple times for the same application, the last call tak
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | ---- | ---------------------------------------- | | -------- | -------- | --------- | ---------------------------------------- |
| interval | string | Yes | Interval at which the callback is invoked to return the gyroscope sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios.| | interval | string | Yes | Interval at which the callback is invoked to return the gyroscope sensor data.<br>The default value is **normal**. The options are as follows:<br>- **game**: called at an interval of 20 ms, which is applicable to gaming scenarios.<br>- **ui**: called at an interval of 60 ms, which is applicable to UI updating scenarios.<br>- **normal**: called at an interval of 200 ms, which is applicable to power-saving scenarios. |
| success | Function | Yes | Called when the gyroscope sensor data changes. | | success | Function | Yes | Called when the gyroscope sensor data changes. |
| fail | Function | No | Callback upon failure. | | fail | Function | No | Callback upon failure. |
Return values of the success callback Return values of the success callback
| Name | Type | Description | | Name | Type | Description |
| ---- | ------ | --------- | | ---- | ------ | ---------------------------------------- |
| x | number | Rotation angular velocity of the X axis.| | x | number | Rotation angular velocity of the X axis. |
| y | number | Rotation angular velocity of the Y axis.| | y | number | Rotation angular velocity of the Y axis. |
| z | number | Rotation angular velocity of the Z axis.| | z | number | Rotation angular velocity of the Z axis. |
**Example** **Example**
......
# Facial Authentication
The **userIAM.faceAuth** module provides APIs for face enrollment.
> **NOTE**
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
> The APIs provided by this module are system APIs.
## Modules to Import
```js
import userIAM_faceAuth from '@ohos.userIAM.faceAuth';
```
## FaceAuthManager
Provides APIs for facial authentication management.
### constructor
constructor()
A constructor used to create a **FaceAuthManager** object.
**System capability**: SystemCapability.UserIAM.UserAuth.FaceAuth
**Return value**
| Type | Description |
| ---------------------- | -------------------- |
| [FaceAuthManager](#faceauthmanager) | **FaceAuthManager** object.|
**Example**
```js
import userIAM_faceAuth from '@ohos.userIAM.faceAuth';
let faceAuthManager = new userIAM_faceAuth.FaceAuthManager()
```
### setSurfaceId
setSurfaceId(surfaceId: string): ResultCode;
Sets an [XComponent surface ID](../arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid) for the face preview page in the face enrollment process.
**System capability**: SystemCapability.UserIAM.UserAuth.FaceAuth
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | ---------------------------------- | ---- | -------------------------- |
| surfaceId | string | Yes | ID of the surface held by the [XComponent](../arkui-ts/ts-basic-components-xcomponent.md#getxcomponentsurfaceid).|
**Return value**
| Type | Description |
| ---------- | ------------------------------------------------------------ |
| [ResultCode](#resultcode) | Operation result code.|
**Example**
```js
import userIAM_faceAuth from '@ohos.userIAM.faceAuth';
let faceAuthManager = new userIAM_faceAuth.FaceAuthManager()
faceAuthManager.setSurfaceId("0");
```
## ResultCode
Enumerates the operation result codes.
**System capability**: SystemCapability.UserIAM.UserAuth.FaceAuth
| Name | Default Value| Description |
| ----------------------- | ------ | -------------------- |
| SUCCESS | 0 | The operation is successful. |
| FAIL | 1 | The operation fails. |
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
- [Environment Setup](faqs-environment-setup.md) - [Environment Setup](faqs-environment-setup.md)
- [Compilation and Building](faqs-building.md) - [Compilation and Building](faqs-building.md)
- [Burning](faqs-burning.md) - [Burning](faqs-burning.md)
- [File Management Development](faqs-file-management.md)
- [Data Management Development](faqs-data-management.md)
- [Kernel](faqs-kernel.md) - [Kernel](faqs-kernel.md)
- [Porting](faqs-porting.md) - [Porting](faqs-porting.md)
- [Startup](faqs-startup.md) - [Startup](faqs-startup.md)
......
此差异已折叠。
此差异已折叠。
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
- [三四方库使用常见问题](faqs-third-party-library.md) - [三四方库使用常见问题](faqs-third-party-library.md)
- [IDE使用常见问题](faqs-ide.md) - [IDE使用常见问题](faqs-ide.md)
- [hdc_std命令使用常见问题](faqs-hdc-std.md) - [hdc_std命令使用常见问题](faqs-hdc-std.md)
- [开发板](faqs-development-board.md) - [开发板使用常见问题](faqs-development-board.md)
...@@ -20,5 +20,5 @@ display.getDefaultDisplay((err, data) => { ...@@ -20,5 +20,5 @@ display.getDefaultDisplay((err, data) => {
} }
console.info('Test Succeeded in obtaining the default display object. Data:' + JSON.stringify(data)); console.info('Test Succeeded in obtaining the default display object. Data:' + JSON.stringify(data));
console.info('Test densityDPI:' + JSON.stringify(data.densityDPI)); console.info('Test densityDPI:' + JSON.stringify(data.densityDPI));
});https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis/js-apis-device-info.md) });
``` ```
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册