未验证 提交 bf46e39b 编写于 作者: O openharmony_ci 提交者: Gitee

!3223 3.1Release分支开发指南英文同步:无需翻译

Merge pull request !3223 from 葛亚芳/OpenHarmony-3.1-Release
......@@ -15,7 +15,7 @@ Call **createDistributedObject()** to create a distributed data object instance.
**Table 1** API for creating a distributed data object instance
| Package| API| Description|
| -------- | -------- | -------- |
| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.|
| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.<br>- &nbsp;**source**: attributes of the **distributedObject** set.<br>- &nbsp;**DistributedObject**: returns the distributed object created.|
### Generating a Session ID
......@@ -33,7 +33,7 @@ Call setSessionId() to set the session ID for a distributed data object. The ses
**Table 3** API for setting a session ID
| Class| API| Description|
| -------- | -------- | -------- |
| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.|
| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.<br>&nbsp;**sessionId**: ID of a distributed object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.|
### Observing Data Changes
......@@ -43,7 +43,7 @@ Call **on()** to subscribe to data changes of a distributed data object. When th
| Class| API| Description|
| -------- | -------- | -------- |
| DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Subscribes to data changes.|
| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Unsubscribes from data changes.|
| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array&lt;string&gt; }>): void | Unsubscribes from data changes. Callback used to return changes of the distributed object. If this parameter is not specified, all callbacks related to data changes will be unregistered.|
### Observing Online or Offline Status
......@@ -72,6 +72,7 @@ The following example shows how to implement a distributed data object synchroni
```js
var local_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true,
parent:undefined, list:undefined});
var sessionId = distributedObject.genSessionId();
```
......@@ -82,13 +83,13 @@ The following example shows how to implement a distributed data object synchroni
```js
// Local object
var local_object = distributedObject.createDistributedObject({name:"jack", age:18, isVis:true,
parent:{mother:"jack mom",father:"jack Dad"},[{mother:"jack mom"}, {father:"jack Dad"}]};
local_object.setsessionId(sessionId);
parent:{mother:"jack mom",father:"jack Dad"},list:[{mother:"jack mom"}, {father:"jack Dad"}]});
local_object.setSessionId(sessionId);
// Remote object
var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true,
parent:undefined, list:undefined});
remote_object.setsessionId(sessionId);
remote_object.setSessionId(sessionId);
// After obtaining that the device status goes online, the remote object synchronizes data. That is, name changes to jack and age to 18.
```
......@@ -97,7 +98,7 @@ The following example shows how to implement a distributed data object synchroni
The sample code is as follows:
```js
changeCallback : function (sessionId, changeData) {
function changeCallback(sessionId, changeData) {
console.info("change" + sessionId);
if (changeData != null && changeData != undefined) {
......@@ -147,7 +148,7 @@ The following example shows how to implement a distributed data object synchroni
8. Subscribe to the status (online/offline) changes of the distributed data object. A callback will be invoked to report the status change when the target distributed data object goes online or offline.
The sample code is as follows:
```js
statusCallback : function (sessionId, networkId, status) {
function statusCallback(sessionId, networkId, status) {
this.response += "status changed " + sessionId + " " + status + " " + networkId;
}
......@@ -157,12 +158,12 @@ The following example shows how to implement a distributed data object synchroni
The sample code is as follows:
```js
// Unsubscribe from changeCallback.
local_object.off("status", changeCallback);
// Unsubscribe from statusCallback.
local_object.off("status", statusCallback);
// unsubscribe from all status change callbacks.
local_object.off("status");
```
10. Remove the distributed data object from the synchronization network. After the distributed data object is removed from the network, the data changes on the local end will not be synchronized to the remote end.
10. Remove a distributed data object from the synchronization network. After the distributed data object is removed from the network, the data changes on the local end will not be synchronized to the remote end.
The sample code is as follows:
```js
......
......@@ -7,7 +7,7 @@ On the basis of the SQLite database, the relational database (RDB) allows you to
## Available APIs
**Creating and Deleting an RDB Store**
### Creating or Deleting an RDB Store
The following table describes the APIs available for creating and deleting an RDB store.
......@@ -17,51 +17,55 @@ The following table describes the APIs available for creating and deleting an RD
| -------- | -------- |
|getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number,&nbsp;callback:&nbsp;AsyncCallback&lt;RdbStore&gt;):&nbsp;void | Obtains an RDB store. This method uses a callback to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>-&nbsp;**config**: configuration of the RDB store.<br>-&nbsp;**version**: RDB version.<br>-&nbsp;**callback**: callback invoked to return the RDB store obtained.|
|getRdbStore(config:&nbsp;StoreConfig,&nbsp;version:&nbsp;number):&nbsp;Promise&lt;RdbStore&gt; | Obtains an RDB store. This method uses a promise to return the result. You can set parameters for the RDB store based on service requirements, and then call APIs to perform data operations.<br>-&nbsp;**config**: configuration of the RDB store.<br>-&nbsp;**version**: RDB version.|
|deleteRdbStore(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void | Deletes an RDB store. This method uses a callback to return the result. <br>-&nbsp;**name**: RDB store to delete.<br>-&nbsp;**callback**: callback invoked to return the result. If the RDB store is deleted, **true** will be returned. Otherwise, **false** will be returned.|
|deleteRdbStore(name:&nbsp;string,&nbsp;callback:&nbsp;AsyncCallback&lt;void&gt;):&nbsp;void | Deletes an RDB store. This method uses a callback to return the result. <br>-&nbsp;**name**: RDB store to delete.<br>-&nbsp;**callback**: callback invoked to return the result.|
| deleteRdbStore(name:&nbsp;string):&nbsp;Promise&lt;void&gt; | Deletes an RDB store. This method uses a promise to return the result.<br>-&nbsp;**name**: RDB store to delete.|
**Managing Data in an RDB Store**
### Managing Data in an RDB Store
The RDB provides APIs for inserting, deleting, updating, and querying data in the local RDB store.
- **Inserting data**<br/>
- **Inserting data**
The RDB provides APIs for inserting data through a **ValuesBucket** in a data table. If the data is inserted, the row ID of the data inserted will be returned; otherwise, **-1** will be returned.
**Table 2** APIs for inserting data
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | insert(name:&nbsp;string,&nbsp;values:&nbsp;ValuesBucket,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Inserts a row of data into a table. This method uses a callback to return the result.<br>-&nbsp;**name**: name of the target table.<br>-&nbsp;**values**: data to be inserted into the table.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, the row ID will be returned. Otherwise, **-1** will be returned.|
| RdbStore | insert(name:&nbsp;string,&nbsp;values:&nbsp;ValuesBucket):&nbsp;Promise&lt;number&gt; | Inserts a row of data into a table. This method uses a promise to return the result.<br>-&nbsp;**name**: name of the target table.<br>-&nbsp;**values**: data to be inserted into the table.|
- **Updating data**<br/>
- **Updating data**
Call the **update()** method to pass new data and specify the update conditions by using **RdbPredicates**. If the data is updated, the number of rows of the updated data will be returned; otherwise, **0** will be returned.
**Table 3** APIs for updating data
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | update(values:&nbsp;ValuesBucket,&nbsp;rdbPredicates:&nbsp;RdbPredicates,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**values**: data to update, which is stored in a **ValuesBucket**.<br>-&nbsp;**rdbPredicates**: conditions for updating data.<br>-&nbsp;**callback**: callback invoked to return the number of rows updated.|
| RdbStore | update(values:&nbsp;ValuesBucket,&nbsp;rdbPredicates:&nbsp;RdbPredicates):&nbsp;Promise | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**values**: data to update, which is stored in a **ValuesBucket**.<br>-&nbsp;**rdbPredicates**: conditions for updating data.|
- **Deleting data**<br/>
- **Deleting data**
Call the **delete()** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the number of rows of the deleted data will be returned; otherwise, **0** will be returned.
**Table 4** APIs for deleting data
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | delete(rdbPredicates:&nbsp;RdbPredicates,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**rdbPredicates**: conditions for deleting data.<br>-&nbsp;**callback**: callback invoked to return the number of rows deleted.|
| RdbStore | delete(rdbPredicates:&nbsp;RdbPredicates):&nbsp;Promise | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.<br>-&nbsp;**rdbPredicates**: conditions for deleting data.|
- **Querying data**
- **Querying data**<br/>
You can query data in an RDB store in either of the following ways:
- Call the **query()** method to query data based on the predicates, without passing any SQL statement.
- Run the native SQL statement.
**Table 5** APIs for querying data
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | query(rdbPredicates:&nbsp;RdbPredicates,&nbsp;columns:&nbsp;Array,&nbsp;callback:&nbsp;AsyncCallback&lt;ResultSet&gt;):&nbsp;void | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.<br>-&nbsp;**rdbPredicates**: conditions for querying data.<br>-&nbsp;**columns**: columns to query. If this parameter is not specified, the query applies to all columns.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
......@@ -69,7 +73,7 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th
| RdbStore | querySql(sql:&nbsp;string,&nbsp;bindArgs:&nbsp;Array&lt;ValueType&gt;,&nbsp;callback:&nbsp;AsyncCallback&lt;ResultSet&gt;):void | Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.<br>-&nbsp;**sql**: SQL statement.<br>-&nbsp;**bindArgs**: arguments in the SQL statement.<br>-&nbsp;**callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.|
| RdbStore | querySql(sql:&nbsp;string,&nbsp;bindArgs?:&nbsp;Array&lt;ValueType&gt;):Promise&lt;ResultSet&gt; | Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.<br>-&nbsp;**sql**: SQL statement.<br>-&nbsp;**bindArgs**: arguments in the SQL statement.|
**Using Predicates**
### Using Predicates
The RDB provides **RdbPredicates** for you to set database operation conditions.
......@@ -108,12 +112,12 @@ The RDB provides **RdbPredicates** for you to set database operation conditions.
| RdbPredicates | in(field:&nbsp;string,&nbsp;value:&nbsp;Array&lt;ValueType&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value within the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: array of **ValueType** to match.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
| RdbPredicates | notIn(field:&nbsp;string,&nbsp;value:&nbsp;Array&lt;ValueType&gt;):&nbsp;RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array&#60;ValueType&#62;** and value out of the specified range.<br>-&nbsp;**field**: column name in the database table.<br>-&nbsp;**value**: array of **ValueType** to match.<br>-&nbsp;**RdbPredicates**: returns a **RdbPredicates** object that matches the specified field.|
**Using the Result Set**
### Using the Result Set
A result set can be regarded as a row of data in the queried results. It allows you to traverse and access the data you have queried. The following table describes the external APIs of **ResultSet**.
> ![icon-notice.gif](../public_sys-resources/icon-notice.gif) **NOTICE**<br/>
> After a result set is used, you must call the **close()** method to close it explicitly.
> After a result set is used, you must call the **close()** method to close it explicitly.**
**Table 7** APIs for using the result set
......@@ -133,26 +137,13 @@ A result set can be regarded as a row of data in the queried results. It allows
| ResultSet | isColumnNull(columnIndex:&nbsp;number):&nbsp;boolean | Checks whether the value in the specified column of the current row is null.|
| ResultSet | close():&nbsp;void | Closes the result set.|
**Changing the Encryption Key for an RDB Store**
You can encrypt an RDB store.
When creating an RDB store, you can add a key for security purposes. After that, the RDB store can be accessed only with the correct key. You can change the key but cannot delete it.
Once an RDB store is created without a key, you can no longer add a key for it.
**Table 8** APIs for changing the encryption key
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array,&nbsp;callback:&nbsp;AsyncCallback&lt;number&gt;):void; | Changes the encryption key for this RDB store. This method uses a callback to return the result. If the operation is successful, **0** will be returned. Otherwise, a non-zero value will be returned.|
| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array):&nbsp;Promise&lt;number&gt;; | Changes the encryption key for this RDB store. This method uses a promise to return the result. If the operation is successful, **0** will be returned. Otherwise, a non-zero value will be returned.|
### Setting Distributed Tables
**Setting Distributed Tables**
You can set a list of distributed tables for data operations across devices.
**Table 9** APIs for setting distributed tables
**Table 8** APIs for setting distributed tables
| Class| API| Description|
| -------- | -------- | -------- |
......@@ -163,7 +154,7 @@ You can set a list of distributed tables for data operations across devices.
You can obtain the distributed table name for a remote device based on the local table name. The distributed table name can be used to query the RDB store of the remote device.
**Table 10** API for obtaining the distributed table name of a remote device
**Table 9** APIs for obtaining the distributed table name of a remote device
| Class| API| Description|
| -------- | -------- | -------- |
......@@ -172,17 +163,16 @@ You can obtain the distributed table name for a remote device based on the local
**Synchronizing Data Between Devices**
**Table 11** APIs for synchronizing data between devices
**Table 10** APIs for synchronizing data between devices
| Class| API| Description|
| -------- | -------- | -------- |
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback<Array<[string, number]>>): void;| Synchronizes data between devices. This method uses a callback to return the result.<br>-&nbsp;**mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>-&nbsp;**predicates**: data and devices to be synchronized.<br>-&nbsp;**callback**: callback invoked to return the result. In the result, **string** indicates the device ID, and **number** indicates the synchronization status of each device. The value **0** indicates a success, and other values indicate a failure.|
| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates): Promise<Array<[string, number]>>;| Synchronizes data between devices. This method uses a promise to return the result.<br>-&nbsp;**mode**: data synchronization mode. **SYNC\_MODE\_PUSH** means to push data from the local device to a remote device. **SYNC\_MODE\_PULL** means to pull data from a remote device to the local device.<br>-&nbsp;**predicates**: data and devices to be synchronized. |
**Registering an RDB Store Observer**
**Table 12** API for registering an observer
**Table 11** API for registering an observer
| Class| API| Description|
| -------- | -------- | -------- |
......@@ -190,7 +180,7 @@ You can obtain the distributed table name for a remote device based on the local
**Unregistering an RDB Store Observer**
**Table 13** API for unregistering an observer
**Table 12** API for unregistering an observer
| Class| API| Description|
| -------- | -------- | -------- |
......@@ -211,9 +201,10 @@ You can obtain the distributed table name for a remote device based on the local
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",}
let rdbStore = await data_rdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST);
data_rdb.getRdbStore(STORE_CONFIG, 1, function (err, rdbStore) {
rdbStore.executeSql(SQL_CREATE_TABLE)
console.info('create table done.')
})
```
2. Insert data.
......@@ -238,16 +229,16 @@ You can obtain the distributed table name for a remote device based on the local
```
let predicates = new data_rdb.RdbPredicates("test");
predicates.equalTo("name", "Tom")
let resultSet = await rdbStore.query(predicates)
resultSet.goToFirstRow()
const id = await resultSet.getLong(resultSet.getColumnIndex("id"))
const name = await resultSet.getString(resultSet.getColumnIndex("name"))
const age = await resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType"))
resultSet.close()
let promisequery = rdbStore.query(predicates)
promisequery.then((resultSet) => {
resultSet.goToFirstRow()
const id = resultSet.getLong(resultSet.getColumnIndex("id"))
const name = resultSet.getString(resultSet.getColumnIndex("name"))
const age = resultSet.getLong(resultSet.getColumnIndex("age"))
const salary = resultSet.getDouble(resultSet.getColumnIndex("salary"))
const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType"))
resultSet.close()
})
```
4. Set the distributed tables to be synchronized.
......@@ -261,7 +252,7 @@ You can obtain the distributed table name for a remote device based on the local
promise.then(() => {
console.info("setDistributedTables success.")
}).catch((err) => {
console.info("setDistributedTables failed."")
console.info("setDistributedTables failed.")
})
```
......@@ -276,7 +267,7 @@ You can obtain the distributed table name for a remote device based on the local
let predicate = new data_rdb.RdbPredicates('test')
predicate.inDevices(['12345678abcde'])
let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate)
promise.then(result) {
promise.then((result) => {
console.log('sync done.')
for (let i = 0; i < result.length; i++) {
console.log('device=' + result[i][0] + ' status=' + result[i][1])
......
......@@ -170,9 +170,9 @@ You can set a USB device as a host to connect to a device for data transfer. The
var pipe = usb.connectDevice(deviceList[0]);
/*
Claim the corresponding interface from deviceList.
interface must be one present in the device configuration.
interface1 must be one present in the device configuration.
*/
usb.claimInterface(pipe , interface, true);
usb.claimInterface(pipe , interface1, true);
```
4. Perform data transfer.
......
......@@ -9,4 +9,5 @@
- Development Fundamentals
- [Directory Structure](package-structure.md)
- [Resource File](basic-resource-file-categories.md)
- [SysCap](syscap.md)
# DevEco Studio \(OpenHarmony\) User Guide
# DevEco Studio (OpenHarmony) User Guide
DevEco Studio is a one-stop, distributed platform developed based on the IntelliJ IDEA Community (Open Source) Edition. It helps you develop versatile all-device, all-scenario applications, offering distributed multi-device development, debugging, and simulation, as well as comprehensive quality and security safeguards.
[DevEco Studio 3.0 Beta3](https://developer.harmonyos.com/cn/develop/deveco-studio#download_beta_openharmony) stands out in the following aspects:
- One-stop information acquisition platform
- A wide range of device project templates
- Efficient code editing
- Visualized UI development
- Bidirectional and instsant UI preview
- High-performing compilation tool Hvigor
- Support for application development based on the device Syscap capability set
- Automatic application signature mechanism
- A diverse array of code debugging and profiling features
For more information, see [DevEco Studio (OpenHarmony) User Guide](https://developer.harmonyos.com/en/docs/documentation/doc-guides/ohos-deveco-studio-overview-0000001263280421).
# SysCap Usage Guidelines
## Overview
### System Capabilities and APIs
SysCap is short for System Capability. It refers to each independent feature in the operating system, such as Bluetooth, Wi-Fi, NFC, and camera. Each system capability corresponds to multiple APIs. These APIs are bound together and their availability depends on the support on the target device. They can also be provided together with the IDE for association.
![image-20220326064841782](figures/image-20220326064841782.png)
### Supported Capability Set, Association Capability Set, and Required Capability Set
The supported capability set, association capability set, and required capability set are collections of system capabilities.
The supported capability set covers the device capabilities, and the required capability set covers the application capabilities. If the capability set required by application A is a subset of the capability set supported by device N, application A can be distributed to device N for installation and running. Otherwise, application A cannot be distributed.
The association capability set covers the system capabilities of APIs that can be associated by the IDE during application development.
![image-20220326064913834](figures/image-20220326064913834.png)
### Devices and Supported Capability Sets
Each device provides a capability set according to its hardware capability.
The SDK classifies devices into general devices and custom devices. The general devices' supported capability set is defined by OpenHarmony, and the custom devices' is defined by device vendors.
![image-20220326064955505](figures/image-20220326064955505.png)
### Mapping Between Devices and SDK Capabilities
The SDK provides full APIs for the IDE. The IDE identifies the supported capability set based on the devices supported by the project, filters the APIs contained in the capability set, and provides the supported APIs for association (to autocomplete input).
![image-20220326065043006](figures/image-20220326065043006.png)
## How to Develop
### Importing the PCID
DevEco Studio allows PCID imports for projects. After the imported PCID file is decoded, the output SysCap is written into the **syscap.json** file.
Right-click the project directory and choose **Import Product Compatibility ID** from the shortcut menu to upload the PCID file and import it to the **syscap.json** file.
![20220329-103626](figures/20220329-103626.gif)
### Configuring the Association Capability Set and Required Capability Set
The IDE automatically configures the association capability set and required capability set based on the settings supported by the created project. You can modify the capability sets when necessary.
For the association capability set, you can use more APIs in the IDE by adding more system capabilities. Note that these APIs may not be supported on the device. Therefore, you need to check whether these APIs are supported before using them.
Exercise caution when modifying the required capability set. Incorrect modifications may cause the application to unable to be distributed to the target device.
```
/* syscap.json */
{
devices: {
general: [ /* Each general device corresponds to a SysCap capability set. Multiple general devices can be configured.*/
"car,
...
],
custom: [ /* Vendor-defined device*/
{
"Custom device": [
"SystemCapability.Communication.SoftBus.Core",
...
]
},
...
]
},
development: { /* The SysCap set in addedSysCaps and the SysCap set supported by each device configured in devices form the association capability set.*/
addedSysCaps: [
"SystemCapability.Location.Location.Lite",
...
]
},
production: { /* Used to generate the RPCID. Exercise caution when adding this parameter. Under incorrect settings, applications may fail to be distributed to target devices.*/
addedSysCaps: [], // Intersection of SysCap sets supported by devices configured in devices. It is the required capability set with addedSysCaps set and removedSysCaps set.
removedSysCaps: [] // When the required capability set is a capability subset of a device, the application can be distributed to the device.
}
}
```
### Single-Device Application Development
By default, the association capability set and required system capability set of the application are the same as the supported system capability set of the device. Exercise caution when modifying the required capability set.
![image-20220326065124911](figures/image-20220326065124911.png)
### Cross-Device Application Development
By default, the association capability set of the application is the union of multiple devices' supported capability sets. The capability sets must be the intersection.
![image-20220326065201867](figures/image-20220326065201867.png)
### Checking Whether an API Is Available
To check whether a project supports a specific SysCap, you can use **canIUse**.
```
if (canIUse("SystemCapability.ArkUI.ArkUI.Full")) {
console.log("The application supports SystemCapability.ArkUI.ArkUI.Full.");
} else {
Console.log("The application does not support SystemCapability.ArkUI.ArkUI.Full".);
}
```
You can import a module. If the current device does not support the module, the import result is **undefined**. When using an API, you need to check whether the API is available.
```
import geolocation from '@ohos.geolocation';
if (geolocation) {
geolocation.getCurrentLocation((location) => {
console.log(location.latitude, location.longitude);
});
} else {
Console.log('The device does not support location information.');
}
```
### Checking the Differences Between Devices with the Same Capability
The performance of a system capability may vary by device type. For example, a tablet is superior to a smart wearable device in terms of the camera capability.
```
import userAuth from '@ohos.userIAM.userAuth';
const authenticator = userAuth.getAuthenticator();
const result = authenticator.checkAbility('FACE_ONLY', 'S1');
if (result == authenticator.CheckAvailabilityResult.AUTH_NOT_SUPPORT) {
Console.log('The device does not support facial recognition.');
}
// If an unsupported API is forcibly called, an error message is returned, but no syntax error occurs.
authenticator.execute('FACE_ONLY', 'S1', (err, result) => {
if (err) {
console.log(err.message);
return;
}
})
```
### How Are the SysCap Differences Between Devices Generated
The SysCap of devices varies according to the component combination assembled by the product solution vendor. The following figure shows the overall process.
![image-20220326072448840](figures/image-20220326072448840.png)
1. A set of OpenHarmony source code consists of optional and mandatory components. Different components have different system capabilities. In other words, different components represent different SysCaps.
2. In a normalized released SDK, the mapping exists between APIs and SysCap.
3. Product solution vendors can assemble components based on hardware capabilities and product requirements.
4. The components configured for a product can be OpenHarmony components or private components developed by a third party. Because there is mapping between components and SysCap, the SysCap set of the product can be obtained after all components are assembled.
5. The SysCap set is encoded to generate the PCID. You can import the PCID to the IDE and decode it into SysCap. During development, compatibility processing is performed on the SysCap differences of devices.
6. System parameters deployed on devices contain the SysCap set. The system provides native interfaces and application interfaces for components and applications in the system to check whether a SysCap set is available.
7. During application development, the SysCap required by the application is encoded into the Required Product Compatibility ID (RPCID) and written into the application installation package. During application installation, the package manager decodes the RPCID to obtain the SysCap required by the application and compares it with the SysCap of the device. If the SysCap required by the application is met, the application is successfully installed.
8. When an application is running, the **canIUse** API can be used to query the SysCap of a device to ensure compatibility on different devices.
......@@ -7,36 +7,29 @@ WebGL helps you process graphics at the frontend, for example, drawing color gra
## Available APIs
To use WebGL, you must import the following module:
**Table 1** WebGL APIs
```
import webgl from "@ohos.webglnapi";
```
**Table 1** WebGL APIs
| API | Description |
| API| Description|
| -------- | -------- |
| canvas.getContext | Obtains&nbsp;the&nbsp;canvas&nbsp;context. |
| webgl.createBuffer():&nbsp;WebGLBuffer&nbsp;\|&nbsp;null | Creates&nbsp;and&nbsp;initializes&nbsp;a&nbsp;WebGL&nbsp;buffer. |
| webgl.bindBuffer(target:&nbsp;GLenum,&nbsp;buffer:&nbsp;WebGLBuffer&nbsp;\|&nbsp;null):&nbsp;void | Binds&nbsp;the&nbsp;WebGL&nbsp;buffer&nbsp;to&nbsp;the&nbsp;target. |
| webgl.bufferData(target:&nbsp;GLenum,&nbsp;srcData:&nbsp;ArrayBufferView,&nbsp;usage:&nbsp;GLenum,&nbsp;srcOffset:&nbsp;GLuint,&nbsp;length?:&nbsp;GLuint):&nbsp;void | Creates&nbsp;and&nbsp;initializes&nbsp;the&nbsp;WebGL&nbsp;buffer&nbsp;object's&nbsp;data&nbsp;store. |
| webgl.getAttribLocation(program:&nbsp;WebGLProgram,&nbsp;name:&nbsp;string):&nbsp;GLint | Obtains&nbsp;the&nbsp;address&nbsp;of&nbsp;the&nbsp;**attribute**&nbsp;variable&nbsp;in&nbsp;the&nbsp;shader&nbsp;from&nbsp;the&nbsp;given&nbsp;WebGLProgram. |
| webgl.vertexAttribPointer(index:&nbsp;GLuint,&nbsp;size:&nbsp;GLint,&nbsp;type:&nbsp;GLenum,&nbsp;normalized:&nbsp;GLboolean,&nbsp;stride:&nbsp;GLsizei,&nbsp;offset:&nbsp;GLintptr):&nbsp;void | Assigns&nbsp;a&nbsp;**Buffer**&nbsp;object&nbsp;to&nbsp;a&nbsp;variable. |
| webgl.enableVertexAttribArray(index:&nbsp;GLuint):&nbsp;void | Connects&nbsp;a&nbsp;variable&nbsp;to&nbsp;the&nbsp;**Buffer**&nbsp;object&nbsp;allocated&nbsp;to&nbsp;it. |
| webgl.clearColor(red:&nbsp;GLclampf,&nbsp;green:&nbsp;GLclampf,&nbsp;blue:&nbsp;GLclampf,&nbsp;alpha:&nbsp;GLclampf):&nbsp;void | Clears&nbsp;the&nbsp;specified&nbsp;color&nbsp;on&nbsp;the&nbsp;**&lt;canvas&gt;**&nbsp;component. |
| webgl.clear(mask:&nbsp;GLbitfield):&nbsp;void | Clears&nbsp;the&nbsp;**&lt;canvas&gt;**&nbsp;component. |
| webgl.drawArrays(mode:&nbsp;GLenum,&nbsp;first:&nbsp;GLint,&nbsp;count:&nbsp;GLsizei):&nbsp;void | Draws&nbsp;data. |
| webgl.flush():&nbsp;void | Flushes&nbsp;data&nbsp;to&nbsp;the&nbsp;GPU&nbsp;and&nbsp;clears&nbsp;the&nbsp;buffer. |
| webgl.createProgram():&nbsp;WebGLProgram&nbsp;\|&nbsp;null | Creates&nbsp;a&nbsp;**WebGLProgram**&nbsp;object. |
| canvas.getContext | Obtains the canvas context.|
| webgl.createBuffer():&nbsp;WebGLBuffer&nbsp;\|&nbsp;null | Creates and initializes a WebGL buffer.|
| webgl.bindBuffer(target:&nbsp;GLenum,&nbsp;buffer:&nbsp;WebGLBuffer&nbsp;\|&nbsp;null):&nbsp;void | Binds the WebGL buffer to the target.|
| webgl.bufferData(target:&nbsp;GLenum,&nbsp;srcData:&nbsp;ArrayBufferView,&nbsp;usage:&nbsp;GLenum,&nbsp;srcOffset:&nbsp;GLuint,&nbsp;length?:&nbsp;GLuint):&nbsp;void | Creates and initializes the WebGL buffer object's data store.|
| webgl.getAttribLocation(program:&nbsp;WebGLProgram,&nbsp;name:&nbsp;string):&nbsp;GLint | Obtains the address of the **attribute** variable in the shader from the given WebGLProgram.|
| webgl.vertexAttribPointer(index:&nbsp;GLuint,&nbsp;size:&nbsp;GLint,&nbsp;type:&nbsp;GLenum,&nbsp;normalized:&nbsp;GLboolean,&nbsp;stride:&nbsp;GLsizei,&nbsp;offset:&nbsp;GLintptr):&nbsp;void | Assigns a **Buffer** object to a variable.|
| webgl.enableVertexAttribArray(index:&nbsp;GLuint):&nbsp;void | Connects a variable to the **Buffer** object allocated to it.|
| webgl.clearColor(red:&nbsp;GLclampf,&nbsp;green:&nbsp;GLclampf,&nbsp;blue:&nbsp;GLclampf,&nbsp;alpha:&nbsp;GLclampf):&nbsp;void | Clears the specified color on the **\<canvas>** component.|
| webgl.clear(mask:&nbsp;GLbitfield):&nbsp;void | Clears the **\<canvas>** component.|
| webgl.drawArrays(mode:&nbsp;GLenum,&nbsp;first:&nbsp;GLint,&nbsp;count:&nbsp;GLsizei):&nbsp;void | Draws data.|
| webgl.flush():&nbsp;void | Flushes data to the GPU and clears the buffer.|
| webgl.createProgram():&nbsp;WebGLProgram&nbsp;\|&nbsp;null | Creates a **WebGLProgram** object.|
## How to Develop
The following describes how to draw a 2D image without using shaders and how to draw a color triangle using shaders.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> When using WebGL for development, use a real device to ensure the GUI display effect.
......@@ -45,7 +38,6 @@ The following describes how to draw a 2D image without using shaders and how to
To draw a 2D image without using WebGL, that is, to implement CPU rather than GPU drawing, perform the following steps:
1. Create a page layout in the **index.hml** file. The following is an example of the file content:
```
<div class="container">
<canvas ref="canvas1" style="width : 400px; height : 200px; background-color : lightyellow;"></canvas>
......@@ -54,7 +46,6 @@ To draw a 2D image without using WebGL, that is, to implement CPU rather than GP
```
2. Set the page style in the **index.css** file. The following is an example of the file content:
```
.container {
flex-direction: column;
......@@ -72,7 +63,6 @@ To draw a 2D image without using WebGL, that is, to implement CPU rather than GP
```
3. Edit the **index.js** file to add the 2D drawing logic code. The following is an example of the file content:
```
//index.js
export default { // Native API interaction code
......@@ -108,7 +98,7 @@ To draw a 2D image without using WebGL, that is, to implement CPU rather than GP
}
```
**Figure 1** Effect of clicking the button to draw a 2D image
**Figure 1** Effect of clicking the button to draw a 2D image
![en-us_image_0000001192269746](figures/en-us_image_0000001192269746.gif)
......@@ -118,8 +108,7 @@ To draw a 2D image without using WebGL, that is, to implement CPU rather than GP
To use WebGL to draw a color triangle (GPU drawing), perform the following steps:
1. Create a page layout. The following is an example of the **index.hml** file:
1. Create a page layout in the **index.hml** file. The following is an example of the file content:
```
<div class="container">
<canvas ref="canvas1" style="width : 400px; height : 200px; background-color : lightyellow;"></canvas>
......@@ -127,8 +116,7 @@ To use WebGL to draw a color triangle (GPU drawing), perform the following steps
</div>
```
2. Set the page style. The following is an example of the **index.css** file:
2. Set the page style in the **index.css** file. The following is an example of the file content:
```
.container {
flex-direction: column;
......@@ -145,11 +133,9 @@ To use WebGL to draw a color triangle (GPU drawing), perform the following steps
}
```
3. Edit the JavaScript code file to add the logic code for drawing a color triangle. The following is an example of the **index.js** file:
3. Edit the JavaScript code file to add the logic code for drawing a color triangle. The following is an example of the file content:
```
//index.js
import webgl from "@ohos.webglnapi"; // Import the WebGL module.
// WebGL-related predefinition
var gl = {
......@@ -710,6 +696,6 @@ To use WebGL to draw a color triangle (GPU drawing), perform the following steps
```
**Figure 2** Effect of clicking the button to draw a color triangle
**Figure 2** Effect of clicking the button to draw a color triangle
![en-us_image_0000001192429306](figures/en-us_image_0000001192429306.gif)
......@@ -8,7 +8,7 @@ An application can obtain the default display object or all display objects by c
For details about the APIs, see [Display](../reference/apis/js-apis-display.md).
### How to Develop
## How to Develop
Call **getDefaultDisplay(): Promise<Display>** to obtain the default display object. An example code snippet is as follows:
......
# Window Overview
The Window Manager subsystem provides basic capabilities of window and display management. It is the basis for UI display.
The Window Manager subsystem enables multiple applications to use the same physical screen for display and interaction. For each application, you only need to implement the interaction interface in the allocated display area. A window acts as a display container of the application interface, and the Window Manager subsystem organizes the interaction interfaces into a form visible to end users.
The Window Manager subsystem enables multiple applications to use the same physical screen for display and interaction. For each application, you need to design the interaction interface in the fixed window area. A window acts as a display container of the application interface, and the Window Manager subsystem organizes the interaction interfaces into a form visible to end users.
## Basic Concepts
**Immersive**
The colors of the application interface, status bar, and navigation bar are the same to achieve the visual integrity.
**Immersive : ** The colors of the application interface, status bar, and navigation bar are the same to achieve the visual integrity.
## Working Principles
To display a UI on a screen, the application and system need to request a window object from the Window Manager subsystem. This object generally represents a rectangular area on the screen and has attributes such as the position, width, height, and overlay layer. The object also loads the root node of the UI framework in the interface. The UI of the application is loaded and displayed in the window through the root node.
## Constraints
Except the **on** and **off** APIs used for callback subscription and unsubscription, all other window APIs are asynchronous interfaces.
......@@ -158,8 +158,8 @@
以下为取消监听数据变更的代码示例:
```js
//删除上下线回调changeCallback
local_object.off("status", changeCallback);
//删除上下线回调statusCallback
local_object.off("status", statusCallback);
//删除所有的上下线回调
local_object.off("status");
```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册