diff --git a/en/application-dev/database/Readme-EN.md b/en/application-dev/database/Readme-EN.md index 2555d715a720db4389f502176f9c84226717fcce..6184dc593c212732af684fdecbcde73156be82b0 100644 --- a/en/application-dev/database/Readme-EN.md +++ b/en/application-dev/database/Readme-EN.md @@ -7,5 +7,9 @@ - [RDB Overview](database-relational-overview.md) - [RDB Development](database-relational-guidelines.md) - Lightweight Data Store - - [Lightweight Data Store Overview](database-preference-overview.md) - - [Lightweight Data Store Development](database-preference-guidelines.md) \ No newline at end of file + - [Lightweight Data Store Overview](database-distributedobject-overview.md) + - [Lightweight Data Store Development](database-distributedobject-guidelines.md) + + + + \ No newline at end of file diff --git a/en/application-dev/database/database-relational-guidelines.md b/en/application-dev/database/database-relational-guidelines.md index 2411dd2c9a15ce0976587dd3caa74e31e7777ce5..494ebd562b0cf6c241137823e2360122c21f5bea 100644 --- a/en/application-dev/database/database-relational-guidelines.md +++ b/en/application-dev/database/database-relational-guidelines.md @@ -1,671 +1,316 @@ -# RDB Development +# RDB Development -## When to Use +## When to Use -On the basis of the SQLite database, the RDB allows you to operate data with or without native SQL statements. An RDB is also called RDB store. +On the basis of the SQLite database, the relational database (RDB) allows you to operate data with or without native SQL statements. In OpenHarmony, an RDB is also called RDB store. -## Available APIs + +## Available APIs **Creating and Deleting an RDB Store** -The following table describes APIs available for creating and deleting an RDB store. - -**Table 1** APIs for creating and deleting an RDB store - - - - - - - - - - - - - - - - - - - - - - - - -

Class

-

API

-

Description

-

dataRdb

-

getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): void

-

Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a callback to return the result.

-
  • config: configuration of the RDB store.
  • version: version of the RDB store.
  • callback: callback invoked to return the RDB store.
-

dataRdb

-

getRdbStore(config: StoreConfig, version: number): Promise<RdbStore>

-

Obtains an RDB store. You can set parameters for the RDB store based on service requirements, call APIs to perform data operations, and use a promise to return the result.

-
  • config: configuration of the RDB store.
  • version: version of the RDB store.
-

dataRdb

-

deleteRdbStore(name: string, callback: AsyncCallback<void>): void

-

Deletes an RDB store. This method uses a callback to return the result.

-
  • name: name of the RDB store to delete.
  • callback: callback invoked to return the result. If the RDB store is deleted, true will be returned. Otherwise, false will be returned.
-

dataRdb

-

deleteRdbStore(name: string): Promise<void>

-

Deletes an RDB store. This method uses a promise to return the result.

-
  • name: name of the RDB store to delete.
-
+The following table describes the APIs available for creating and deleting an RDB store. -**Managing Data in an RDB Store** +**Table 1** APIs for creating and deleting an RDB store + +| Class| API| Description| +| -------- | -------- | -------- | +| dataRdb | getRdbStore(config: StoreConfig, version: number, callback: AsyncCallback<RdbStore>): 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.
- **config**: configuration of the RDB store.
- **version**: RDB version.
- **callback**: callback invoked to return the RDB store obtained.| +| dataRdb | getRdbStore(config: StoreConfig, version: number): Promise<RdbStore> | 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.
- **config**: configuration of the RDB store.
- **version**: RDB version.| +| dataRdb | deleteRdbStore(name: string, callback: AsyncCallback<void>): void | Deletes an RDB store. This method uses a callback to return the result.
- **name**: RDB store to delete.
- **callback**: callback invoked to return the result. If the RDB store is deleted, **true** will be returned. Otherwise, **false** will be returned.| +| dataRdb | deleteRdbStore(name: string): Promise<void> | Deletes an RDB store. This method uses a promise to return the result.
- **name**: RDB store to delete.| -The RDB provides APIs for inserting, deleting, modifying, and querying data in the local RDB store. - -- **Inserting data** - - The RDB provides methods for inserting data through **ValuesBucket** in a data table. If the data is inserted successfully, the row number of the data inserted is returned; otherwise, **-1** is returned. - - **Table 2** APIs for inserting data to a data table - - - - - - - - - - - - - - - - -

Class

-

API

-

Description

-

RdbStore

-

insert(name: string, values: ValuesBucket, callback: AsyncCallback<number>):void

-

Inserts a row of data into a table. This method uses a callback to return the result.

-
  • name: name of the target table.
  • values: data to be inserted into the table.
  • 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: string, values: ValuesBucket): Promise<number>

-

Inserts a row of data into a table. This method uses a promise to return the result.

-
  • name: name of the target table.
  • values: data to be inserted into the table.
-
- -- **Updating data** - - Call the **update\(\)** method to pass the new data and specify the update conditions by using **RdbPredicates**. If the data is successfully updated, the row number of the updated data is returned; otherwise, **0** is returned. - - **Table 3** APIs for updating data - - - - - - - - - - - - - - - - -

Class

-

API

-

Description

-

RdbStore

-

update(values: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void

-

Updates the data that meets the conditions specified by the RdbPredicates object. This method uses a callback to return the result.

-
  • values: data to update, which is stored in ValuesBucket.
  • rdbPredicates: conditions for updating data.
  • callback: callback invoked to return the number of rows updated.
-

RdbStore

-

update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise

-

Updates the data that meets the conditions specified by the RdbPredicates object. This method uses a promise to return the result.

-
  • values: data to update, which is stored in ValuesBucket.
  • rdbPredicates: conditions for updating data.
-
- -- **Deleting data** - - Call the **delete\(\)** method to delete data meeting the conditions specified by **RdbPredicates**. If the data is deleted, the row number of the deleted data is returned; otherwise, **0** is returned. - - **Table 4** APIs for deleting data - - - - - - - - - - - - - - - - -

Class

-

API

-

Description

-

RdbStore

-

delete(rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void

-

Deletes data based on the conditions specified by RdbPredicates. This method uses a callback to return the result.

-
  • rdbPredicates: conditions for deleting data.
  • callback: callback invoked to return the number of rows deleted.
-

RdbStore

-

delete(rdbPredicates: RdbPredicates): Promise

-

Deletes data based on the conditions specified by RdbPredicates. This method uses a promise to return the result.

-
  • rdbPredicates: conditions for deleting data.
-
- -- **Querying data** - - You can query data in the RDB 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: RdbPredicates, columns: Array, callback: AsyncCallback<ResultSet>): void;

-

Queries data in the database based on specified conditions. This method uses a callback to return the result.

-
  • rdbPredicates: conditions for querying data.
-
  • columns: columns to query. If this parameter is not specified, the query applies to all columns.
  • callback: callback invoked to return the result. If the operation is successful, a ResultSet object will be returned.
-

RdbStore

-

query(rdbPredicates: RdbPredicates, columns: Array): Promise<ResultSet>;

-

Queries data in the database based on specified conditions. This method uses a promise to return the result.

-
  • rdbPredicates: conditions for querying data.
-
  • columns: columns to query. If this parameter is not specified, the query applies to all columns.
-

RdbStore

-

querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void

-

Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.

-
  • sql: SQL statement.
-
  • bindArgs: arguments in the SQL statement.
  • callback: callback invoked to return the result. If the operation is successful, a ResultSet object will be returned.
-

RdbStore

-

querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet>

-

Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.

-
  • sql: SQL statement.
-
  • bindArgs: arguments in the SQL statement.
-
+**Managing Data in an RDB Store** +The RDB provides APIs for inserting, deleting, updating, and querying data in the local RDB store. + +- **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: string, values: ValuesBucket, callback: AsyncCallback<number>):void | Inserts a row of data into a table. This method uses a callback to return the result.
- **name**: name of the target table.
- **values**: data to be inserted into the table.
- **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: string, values: ValuesBucket): Promise<number> | Inserts a row of data into a table. This method uses a promise to return the result.
- **name**: name of the target table.
- **values**: data to be inserted into the table.| + +- **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: ValuesBucket, rdbPredicates: RdbPredicates, callback: AsyncCallback<number>):void | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.
- **values**: data to update, which is stored in a **ValuesBucket**.
- **rdbPredicates**: conditions for updating data.
- **callback**: callback invoked to return the number of rows updated.| + | RdbStore | update(values: ValuesBucket, rdbPredicates: RdbPredicates): Promise | Updates data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.
- **values**: data to update, which is stored in a **ValuesBucket**.
- **rdbPredicates**: conditions for updating data.| + +- **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: RdbPredicates, callback: AsyncCallback<number>):void | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.
- **rdbPredicates**: conditions for deleting data.
- **callback**: callback invoked to return the number of rows deleted.| + | RdbStore | delete(rdbPredicates: RdbPredicates): Promise | Deletes data from the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.
- **rdbPredicates**: conditions for deleting data.| + +- **Querying data** + 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: RdbPredicates, columns: Array, callback: AsyncCallback<ResultSet>): void | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a callback to return the result.
- **rdbPredicates**: conditions for querying data.
- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.
- **callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| + | RdbStore | query(rdbPredicates: RdbPredicates, columns: Array): Promise<ResultSet> | Queries data in the RDB store based on the specified **RdbPredicates** object. This method uses a promise to return the result.
- **rdbPredicates**: conditions for querying data.
- **columns**: columns to query. If this parameter is not specified, the query applies to all columns.| + | RdbStore | querySql(sql: string, bindArgs: Array<ValueType>, callback: AsyncCallback<ResultSet>):void | Queries data in the RDB store using the specified SQL statement. This method uses a callback to return the result.
- **sql**: SQL statement.
- **bindArgs**: arguments in the SQL statement.
- **callback**: callback invoked to return the result. If the operation is successful, a **ResultSet** object will be returned.| + | RdbStore | querySql(sql: string, bindArgs?: Array<ValueType>):Promise<ResultSet> | Queries data in the RDB store using the specified SQL statement. This method uses a promise to return the result.
- **sql**: SQL statement.
- **bindArgs**: arguments in the SQL statement.| **Using Predicates** -The RDB provides **RdbPredicates** for you to set database operation conditions. - -**Table 6** APIs for RDB predicates - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Class

-

API

-

Description

-

RdbPredicates

-

equalTo(field: string, value: ValueType): RdbPredicates

-

Sets the RdbPredicates to match the field with data type ValueType and value equal to the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

notEqualTo(field: string, value: ValueType): RdbPredicates

-

Sets the RdbPredicates to match the field with data type ValueType and value not equal to the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

beginWrap(): RdbPredicates

-

Adds a left parenthesis to the RdbPredicates.

-
  • RdbPredicates: RdbPredicates with a left parenthesis.
-

RdbPredicates

-

endWrap(): RdbPredicates

-

Adds a right parenthesis to the RdbPredicates.

-
  • RdbPredicates: RdbPredicates with a right parenthesis.
-

RdbPredicates

-

or(): RdbPredicates

-

Adds the OR condition to the RdbPredicates.

-
  • RdbPredicates: RdbPredicates with the OR condition.
-

RdbPredicates

-

and(): RdbPredicates

-

Adds the AND condition to the RdbPredicates.

-
  • RdbPredicates: RdbPredicates with the AND condition.
-

RdbPredicates

-

contains(field: string, value: string): RdbPredicats

-

Sets the RdbPredicates to match a string containing the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

beginsWith(field: string, value: string): RdbPredicates

-

Sets the RdbPredicates to match a string that starts with the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

endsWith(field: string, value: string): RdbPredicates

-

Sets the RdbPredicates to match a string that ends with the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

isNull(field: string): RdbPredicates

-

Sets the RdbPredicates to match the field whose value is null.

-
  • field: column name in the database table.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

isNotNull(field: string): RdbPredicates

-

Sets the RdbPredicates to match the field whose value is not null.

-
  • field: column name in the database table.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

like(field: string, value: string): RdbPredicates

-

Sets the RdbPredicates to match a string that is similar to the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

glob(field: string, value: string): RdbPredicates

-

Sets the RdbPredicates to match the specified string.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

between(field: string, low: ValueType, high: ValueType): RdbPredicates

-

Sets the RdbPredicates to match the field with data type ValueType and value within the specified range.

-
  • field: column name in the database table.
  • low: minimum value that matches the RdbPredicates.
  • high: maximum value that matches the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates

-

Sets the RdbPredicates to match the field with data type ValueType and value out of the specified range.

-
  • field: column name in the database table.
  • low: minimum value that matches the RdbPredicates.
  • high: maximum value that matches the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

greaterThan(field: string, value: ValueType): RdbPredicatesgr

-

Sets the RdbPredicates to match the field with data type ValueType and value greater than the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

lessThan(field: string, value: ValueType): RdbPredicates

-

Sets the RdbPredicates to match the field with data type ValueType and value less than the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates

-

Sets the RdbPredicates to match the field with data type ValueType and value greater than or equal to the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates

-

Sets the RdbPredicates to match the field with data type ValueType and value less than or equal to the specified value.

-
  • field: column name in the database table.
  • value: value to match the RdbPredicates.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

orderByAsc(field: string): RdbPredicates

-

Sets the RdbPredicates to match the column with values sorted in ascending order.

-
  • field: column name in the database table.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

orderByDesc(field: string): RdbPredicates

-

Sets the RdbPredicates to match the column with values sorted in descending order.

-
  • field: column name in the database table.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

distinct(): RdbPredicates

-

Sets the RdbPredicates to filter out duplicate records.

-
  • RdbPredicates: RdbPredicates that can filter out duplicate records.
-

RdbPredicates

-

limitAs(value: number): RdbPredicates

-

Sets the RdbPredicates to specify the maximum number of records to match in a column.

-
  • value: maximum number of records in a column.
  • RdbPredicates: RdbPredicates that can be used to set the maximum number of records to match in a column.
-

RdbPredicates

-

offsetAs(rowOffset: number): RdbPredicates

-

Sets the RdbPredicates to specify the start position of the returned result.

-
  • rowOffset: start position of the returned result. The value is a positive integer.
  • RdbPredicates: RdbPredicates object that specifies the start position of the returned result.
-

RdbPredicates

-

groupBy(fields: Array<string>): RdbPredicates

-

Sets the RdbPredicates to group rows that have the same value into summary rows.

-
  • fields: names of the columns grouped for querying data.
  • RdbPredicates: RdbPredicates that groups rows that have the same value.
-

RdbPredicates

-

indexedBy(indexName: string): RdbPredicates

-

Sets the RdbPredicates object to specify the index column.

-
  • indexName: name of the index column.
  • RdbPredicates: RdbPredicates object that specifies the index column.
-

RdbPredicates

-

in(field: string, value: Array<ValueType>): RdbPredicates

-

Sets the RdbPredicates to match the field with data type Array<ValueType> and value within the specified range.

-
  • field: column name in the database table.
-
  • value: array of ValueType to match.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-

RdbPredicates

-

notIn(field: string, value: Array<ValueType>): RdbPredicates

-

Sets the RdbPredicates to match the field with data type Array<ValueType> and value out of the specified range.

-
  • field: column name in the database table.
-
  • value: array of ValueType to match.
  • RdbPredicates: RdbPredicates object that matches the specified field.
-
+The RDB provides **RdbPredicates** for you to set database operation conditions. + +**Table 6** APIs for using RDB store predicates + +| Class| API| Description| +| -------- | -------- | -------- | +| RdbPredicates |inDevices(devices: Array): RdbPredicates | Specifies remote devices on the network with RDB stores to be synchronized.
- **devices**: IDs of the remote devices on the network.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates |inAllDevices(): RdbPredicates | Connects to all remote devices on the network with RDB stores to be synchronized.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | equalTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value equal to the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | notEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value not equal to the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | beginWrap(): RdbPredicates | Adds a left parenthesis to the **RdbPredicates**.
- **RdbPredicates**: returns a **RdbPredicates** with a left parenthesis. | +| RdbPredicates | endWrap(): RdbPredicates | Adds a right parenthesis to the **RdbPredicates**.
- **RdbPredicates**: returns a **RdbPredicates** with a right parenthesis. | +| RdbPredicates | or(): RdbPredicates | Adds the OR condition to the **RdbPredicates**.
- **RdbPredicates**: returns a **RdbPredicates** with the OR condition. | +| RdbPredicates | and(): RdbPredicates | Adds the AND condition to the **RdbPredicates**.
- **RdbPredicates**: returns a **RdbPredicates** with the AND condition. | +| RdbPredicates | contains(field: string, value: string): RdbPredicats | Sets the **RdbPredicates** to match a string containing the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. | +| RdbPredicates | beginsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that starts with the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. | +| RdbPredicates | endsWith(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that ends with the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. | +| RdbPredicates | isNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is null.
- **field**: column name in the database table.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | isNotNull(field: string): RdbPredicates | Sets the **RdbPredicates** to match the field whose value is not null.
- **field**: column name in the database table.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | like(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match a string that is similar to the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. | +| RdbPredicates | glob(field: string, value: string): RdbPredicates | Sets the **RdbPredicates** to match the specified string.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified string. | +| RdbPredicates | between(field: string, low: ValueType, high: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value within the specified range.
- **field**: column name in the database table.
- **low**: minimum value that matches the **RdbPredicates**.
- **high**: maximum value that matches the **RdbPredicates**.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | notBetween(field: string, low: ValueType, high: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value out of the specified range.
- **field**: column name in the database table.
- **low**: minimum value that matches the **RdbPredicates**.
- **high**: maximum value that matches the **RdbPredicates**.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | greaterThan(field: string, value: ValueType): RdbPredicatesgr | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | lessThan(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | greaterThanOrEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value greater than or equal to the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | lessThanOrEqualTo(field: string, value: ValueType): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **ValueType** and value less than or equal to the specified value.
- **field**: column name in the database table.
- **value**: value specified.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | orderByAsc(field: string): RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in ascending order.
- **field**: column name in the database table.
- **RdbPredicates**: returns a **RdbPredicates** object that sorts the values in ascending order. | +| RdbPredicates | orderByDesc(field: string): RdbPredicates | Sets the **RdbPredicates** to match the column with values sorted in descending order.
- **field**: column name in the database table.
- **RdbPredicates**: returns a **RdbPredicates** object that sorts the values in descending order. | +| RdbPredicates | distinct(): RdbPredicates | Sets the **RdbPredicates** to filter out duplicate records.
- **RdbPredicates**: returns a **RdbPredicates** object that can filter out duplicate records. | +| RdbPredicates | limitAs(value: number): RdbPredicates | Sets the **RdbPredicates** to specify the maximum number of records.
- **value**: maximum number of records.
- **RdbPredicates**: returns a **RdbPredicates** object that can be used to set the maximum number of records. | +| RdbPredicates | offsetAs(rowOffset: number): RdbPredicates | Sets the **RdbPredicates** to specify the start position of the returned result.
- **rowOffset**: start position of the returned result. The value is a positive integer.
- **RdbPredicates**: returns a **RdbPredicates** object that specifies the start position of the returned result. | +| RdbPredicates | groupBy(fields: Array<string>): RdbPredicates | Sets the **RdbPredicates** to group rows that have the same value into summary rows.
- **fields**: names of the columns grouped for querying data.
- **RdbPredicates**: returns a **RdbPredicates** object that groups rows with the same value. | +| RdbPredicates | indexedBy(indexName: string): RdbPredicates | Sets the **RdbPredicates** to specify the index column.
- **indexName**: name of the index column.
- **RdbPredicates**: returns a **RdbPredicates** object that specifies the index column. | +| RdbPredicates | in(field: string, value: Array<ValueType>): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array<ValueType>** and value within the specified range.
- **field**: column name in the database table.
- **value**: array of **ValueType** to match.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | +| RdbPredicates | notIn(field: string, value: Array<ValueType>): RdbPredicates | Sets the **RdbPredicates** to match the field with data type **Array<ValueType>** and value out of the specified range.
- **field**: column name in the database table.
- **value**: array of **ValueType** to match.
- **RdbPredicates**: returns a **RdbPredicates** object that matches the specified field. | **Using the Result Set** -A result set can be regarded as rows 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**. - ->![](public_sys-resources/icon-notice.gif) **NOTICE:** ->After a result set is used, you must call the **close\(\)** method to close it explicitly. - -**Table 7** APIs for using the result set - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Class

-

API

-

Description

-

ResultSet

-

goTo(offset:number): boolean

-

Moves the result set forwards or backwards by an offset relative to its current position.

-

ResultSet

-

goToRow(position: number): boolean

-

Moves the result set to a specified row.

-

ResultSet

-

goToNextRow(): boolean

-

Moves the result set to the next row.

-

ResultSet

-

goToPreviousRow(): boolean

-

Moves the result set to the previous row.

-

ResultSet

-

getColumnIndex(columnName: string): number

-

Obtains the column index based on the specified column name.

-

ResultSet

-

getColumnName(columnIndex: number): string

-

Obtains the column name based on the specified column index.

-

ResultSet

-

goToFirstRow(): boolean

-

Checks whether the result set is located in the first row.

-

ResultSet

-

goToLastRow(): boolean

-

Checks whether the result set is located in the last row.

-

ResultSet

-

getString(columnIndex: number): string

-

Obtains the values in the specified column of the current row, in strings.

-

ResultSet

-

getBlob(columnIndex: number): Uint8Array

-

Obtains the values in the specified column of the current row, in a byte array.

-

ResultSet

-

getDouble(columnIndex: number): number

-

Obtains the values in the specified column of the current row, in double.

-

ResultSet

-

isColumnNull(columnIndex: number): boolean

-

Checks whether the values in the specified column of the current row are null.

-

ResultSet

-

close(): void

-

Closes the result set.

-
- -**Encrypting an RDB Store** +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** +> After a result set is used, you must call the **close()** method to close it explicitly. + +**Table 7** APIs for using the result set + +| Class| API| Description| +| -------- | -------- | -------- | +| ResultSet | goTo(offset:number): boolean | Moves the result set forwards or backwards by the specified offset relative to its current position.| +| ResultSet | goToRow(position: number): boolean | Moves the result set to the specified row.| +| ResultSet | goToNextRow(): boolean | Moves the result set to the next row.| +| ResultSet | goToPreviousRow(): boolean | Moves the result set to the previous row.| +| ResultSet | getColumnIndex(columnName: string): number | Obtains the column index based on the specified column name.| +| ResultSet | getColumnName(columnIndex: number): string | Obtains the column name based on the specified column index.| +| ResultSet | goToFirstRow(): boolean | Checks whether the result set is located in the first row.| +| ResultSet | goToLastRow(): boolean | Checks whether the result set is located in the last row.| +| ResultSet | getString(columnIndex: number): string | Obtains the value in the specified column of the current row, in a string.| +| ResultSet | getBlob(columnIndex: number): Uint8Array | Obtains the values in the specified column of the current row, in a byte array.| +| ResultSet | getDouble(columnIndex: number): number | Obtains the values in the specified column of the current row, in double.| +| ResultSet | isColumnNull(columnIndex: number): boolean | Checks whether the value in the specified column of the current row is null.| +| ResultSet | close(): 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 cannot add a key any longer. - -**Table 8** APIs for changing the key - - - - - - - - - - - - - - - - -

Class

-

API

-

Description

-

RdbStore

-

changeEncryptKey(newEncryptKey:Uint8Array, callback: AsyncCallback<number>):void;

-

Changes the encryption key for an RDB store. This method uses a callback to return the result. If the key is changed, 0 is returned. Otherwise, a non-zero value is returned.

-

RdbStore

-

changeEncryptKey(newEncryptKey:Uint8Array): Promise<number>;

-

Changes the encryption key for an RDB store. This method uses a promise to return the result. If the key is changed, 0 is returned. Otherwise, a non-zero value is returned.

-
- -## How to Develop - -1. Create an RDB store. - - 1. Configure the RDB attributes, including the name and storage mode of the database and whether it is read-only. - 2. Initialize the table structure and related data in the database. - 3. Create an RDB store. +Once an RDB store is created without a key, you can no longer add a key for it. - The sample code is as follows: +**Table 8** APIs for changing the encryption key - ``` - import dataRdb from '@ohos.data.rdb'; - - 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 dataRdb.getRdbStore(STORE_CONFIG, 1); - await rdbStore.executeSql(CREATE_TABLE_TEST); - ``` +| Class| API| Description| +| -------- | -------- | -------- | +| RdbStore | changeEncryptKey(newEncryptKey:Uint8Array, callback: AsyncCallback<number>):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): Promise<number>; | 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** + +You can set a list of distributed tables for data operations across devices. + +**Table 9** APIs for setting distributed tables + +| Class| API| Description| +| -------- | -------- | -------- | +| RdbStore | setDistributedTables(tables: Array, callback: AsyncCallback): void;| Sets a list of distributed tables. This method uses a callback to return the result.
-  **tables**: names of the distributed tables to set.
- **callback**: callback invoked to return the result.| +| RdbStore | setDistributedTables(tables: Array): Promise; | Sets a list of distributed tables. This method uses a promise to return the result.
-  **tables**: names of the distributed tables to set.| + +**Obtaining the Distributed Table Name for a Remote Device** + +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 + +| Class| API| Description| +| -------- | -------- | -------- | +| RdbStore | obtainDistributedTableName(device: string, table: string, callback: AsyncCallback): void; | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is used to query the RDB store of the remote device. This method uses a callback to return the result.
- **device**: remote device.
-  **table**: local table name.
-  **callback**: callback used to return the result. If the operation is successful, the distributed table name of the remote device will be returned. | +| RdbStore | obtainDistributedTableName(device: string, table: string): Promise; | Obtains the distributed table name for a remote device based on the local table name. The distributed table name is used to query the RDB store of the remote device. This method uses a promise to return the result.
- **device**: remote device.
-  **table**: local table name.| + +**Synchronizing Data Between Devices** + +**Table 11** APIs for synchronizing data between devices + +| Class| API| Description| +| -------- | -------- | -------- | +| RdbStore | sync(mode: SyncMode, predicates: RdbPredicates, callback: AsyncCallback>): void;| Synchronizes data between devices. This method uses a callback to return the result.
- **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.
- **predicates**: data and devices to be synchronized.
- **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>;| Synchronizes data between devices. This method uses a promise to return the result.
- **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.
- **predicates**: data and devices to be synchronized. | + + +**Registering an RDB Store Observer** -2. Insert data. +**Table 12** API for registering an observer - 1. Create a **ValuesBucket** object to store the data you need to insert. - 2. Call the **insert\(\)** method to insert data into the RDB store. +| Class| API| Description| +| -------- | -------- | -------- | +| RdbStore |on(event: 'dataChange', type: SubscribeType, observer: Callback>): void;| Registers an observer for this RDB store to subscribe to distributed data changes. When data in the RDB store changes, a callback will be invoked to return the data changes.
- **type**: subscription type. **SUBSCRIBE\_TYPE\_REMOTE** means to subscribe to remote data changes.
- **observer**: observer that listens for data changes in the RDB store.| + +**Unregistering an RDB Store Observer** + +**Table 13** API for unregistering an observer + +| Class| API| Description| +| -------- | -------- | -------- | +| RdbStore |off(event:'dataChange', type: SubscribeType, observer: Callback>): void;| Unregisters the observer of the specified type for the RDB store. This method uses a callback to return the result.
-  **type**: subscription type. **SUBSCRIBE\_TYPE\_REMOTE** means to subscribe to remote data changes.
-  **observer**: observer to unregister.| + + +## How to Develop + +1. Create an RDB store. + 1. Configure the RDB store attributes, including the RDB store name, storage mode, and whether read-only mode is used. + 2. Initialize the table structure and related data in the RDB store. + 3. Create the RDB store. + + The sample code is as follows: + + ``` + import dataRdb from '@ohos.data.rdb'; + + 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 dataRdb.getRdbStore(STORE_CONFIG, 1); + await rdbStore.executeSql(CREATE_TABLE_TEST); + ``` + +2. Insert data. + 1. Create a **ValuesBucket** to store the data you need to insert. + 2. Call the **insert()** method to insert data into the RDB store. + + The sample code is as follows: + + ``` + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8,} + let insertPromise = rdbStore.insert("test", valueBucket) + ``` + +3. Query data. + 1. Create an **RdbPredicates** object to specify query conditions. + 2. Call the **query()** method to query data. + 3. Call the **ResultSet()** method to obtain the query result. + + The sample code is as follows: + + ``` + let predicates = new dataRdb.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() + ``` + +4. Set the distributed tables to be synchronized. + 1. Set the distributed tables. + 2. Check whether the setting is successful. + + The sample code is as follows: + + ``` + let promise = rdbStore.setDistributedTables(["test"]) + promise.then(() => { + console.info("setDistributedTables success.") + }).catch((err) => { + console.info("setDistributedTables failed."") + }) + ``` + + 5. Synchronize data across devices. + 1. Constructs an **RdbPredicates** object to specify remote devices within the network to be synchronized. + 2. Call the **sync()** method to synchronize data. + 3. Check whether the data synchronization is successful. The sample code is as follows: ``` - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket = {"name": "Tom", "age": 18, "salary": 100.5, "blobType": u8,} - let insertPromise = rdbStore.insert("test", valueBucket) + let predicate = new dataRdb.RdbPredicates('test') + predicate.inDevices(['12345678abcde']) + let promise = rdbStore.sync(rdb.SyncMode.SYNC_MODE_PUSH, predicate) + 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]) + } + }).catch((err) => { + console.log('sync failed') + }) ``` -3. Query data. - - 1. Create an **RdbPredicates** object to specify query conditions. - 2. Call the **query \(\)** method to query data in the RDB store. - 3. Call the **ResultSet\(\)** method to obtain the query result. +6. Subscribe to distributed data. + 1. Register an observer to listen for distributed data changes. + 2. When data in the RDB store changes, a callback will be invoked to return the data changes. The sample code is as follows: ``` - let predicates = new dataRdb.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() + function storeObserver(devices) { + for (let i = 0; i < devices.length; i++) { + console.log('device=' + device[i] + ' data changed') + } + } + try { + rdbStore.on('dataChange', rdb.SubscribeType.SUBSCRIBE_TYPE_REMOTE, storeObserver) + } catch (err) { + console.log('register observer failed') + } ``` +7. Query data across devices. + 1. Obtain the distributed table name for a remote device based on the local table name. + 2. Call the **ResultSet()** method to obtain the query result. + + The sample code is as follows: + ``` + let tableName = rdbStore.obtainDistributedTableName(deviceId, "test"); + let resultSet = rdbStore.querySql("SELECT * FROM " + tableName) + ``` diff --git a/en/application-dev/reference/apis/Readme-EN.md b/en/application-dev/reference/apis/Readme-EN.md index 0c9b2efa1db28346d5d2ce1b22aee2d5047b186d..4e072772748b27c506c29b5ecf6d6fc8c3c2f1b3 100644 --- a/en/application-dev/reference/apis/Readme-EN.md +++ b/en/application-dev/reference/apis/Readme-EN.md @@ -36,6 +36,7 @@ - [App Storage Statistics](js-apis-storage-statistics.md) - [Volume Management](js-apis-volumemanager.md) - Account Management + - [OS Account Management](js-apis-osAccount.md) - [Distributed Account Management](js-apis-distributed-account.md) - [App Account Management](js-apis-appAccount.md) - Telephony Service diff --git a/en/application-dev/reference/apis/js-apis-osAccount.md b/en/application-dev/reference/apis/js-apis-osAccount.md new file mode 100644 index 0000000000000000000000000000000000000000..cd5922478959ba0345b76ac7e69d62f65e290123 --- /dev/null +++ b/en/application-dev/reference/apis/js-apis-osAccount.md @@ -0,0 +1,1647 @@ +# OS Account Management + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. + + +## Modules to Import + +``` +import account_osAccount from '@ohos.account.osAccount'; +``` + +## System Capabilities + +SystemCapability.Account.OsAccount + +## account_osAccount.getAccountManager + +getAccountManager(): AccountManager + +Obtains an **AccountManager** instance. + +- Return value + | Type| Description| + | -------- | -------- | + | [AccountManager](#accountmanager) | **AccountManager** instance obtained.| + +- Example + ``` + const accountManager = account_osAccount.getAccountManager(); + ``` + +## OsAccountType +Enumerates OS account types. + | Name| Default Value| Description| + | -------- | -------- | -------- | + | ADMIN | 0 | Administrator account| + | NORMAL | 1 | Normal account| + | GUEST | 2 | Guest account| + +## AccountManager + +Provides methods to manage OS accounts. + +### activateOsAccount + +activateOsAccount(localId: number, callback: AsyncCallback<void>): void + +Activates an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ------------------- | ---- | -------------------- | + | localId | number | Yes | ID of the OS account to activate.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| + +- Example + + Activate OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.activateOsAccount(localId, (err)=>{ + console.log("activateOsAccount err:" + JSON.stringify(err)); + }); + ``` + +### activateOsAccount + +activateOsAccount(localId: number): Promise<void> + +Activates an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------- | ------ | ---- | ------------ | + | localId | number | Yes | ID of the OS account to activate.| + +- Return value + + | Type | Description | + | :------------ | :---------------------------------- | + | Promise<void> | Promise used to return the result.| + +- Example + + Activate OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.activateOsAccount(localId).then(() => { + console.log("activateOsAccount success"); + }).catch((err) => { + console.log("activateOsAccount err:" + JSON.stringify(err)); + }); + ``` + +### isMultiOsAccountEnable + +isMultiOsAccountEnable(callback: AsyncCallback<boolean>): void + +Checks whether multiple OS accounts are supported. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------- | ---- | ------------------------------ | + | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If multiple OS accounts are supported, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.isMultiOsAccountEnable((err, isEnabled) => { + console.log("isMultiOsAccountEnable err: " + JSON.stringify(err)); + console.log('isMultiOsAccountEnable isEnabled: ' + isEnabled); + }); + ``` + +### isMultiOsAccountEnable + +isMultiOsAccountEnable(): Promise<boolean> + +Checks whether multiple OS accounts are supported. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :--------------- | :---------------------------------- | + | Promise<boolean> | Promise used to return the result. If multiple OS accounts are supported, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.isMultiOsAccountEnable().then((isEnabled) => { + console.log('isMultiOsAccountEnable, isEnabled: ' + isEnabled); + }).catch((err) => { + console.log("isMultiOsAccountEnable err: " + JSON.stringify(err)); + }); + ``` + +### isOsAccountActived + +isOsAccountActived(localId: number, callback: AsyncCallback<boolean>): void + +Checks whether an OS account is activated. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------- | ---- | ------------------------------ | + | localId | number | Yes | ID of the target OS account. | + | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the OS account is activated, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + Check whether OS account 100 is activated. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var osLocalId = 100; + accountManager.isOsAccountActived(osLocalId, (err, isActive)=>{ + console.log("isOsAccountActived err:" + JSON.stringify(err)); + console.log("isOsAccountActived isActive:" + isActive); + }); + ``` + +### isOsAccountActived + +isOsAccountActived(localId: number): Promise<boolean> + +Checks whether an OS account is activated. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------- | ------ | ---- | ------------ | + | localId | number | Yes | ID of the target OS account.| + +- Return value + + | Type | Description | + | :--------------- | :---------------------------------- | + | Promise<boolean> | Promise used to return the result. If the OS account is activated, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + Check whether OS account 100 is activated. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var osLocalId = 100; + accountManager.isOsAccountActived(osLocalId).then((isActive) => { + console.log('isOsAccountActived, isActive: ' + isActive); + }).catch((err) => { + console.log("isOsAccountActived err: " + JSON.stringify(err)); + }); + ``` + +### isOsAccountConstraintEnable + +isOsAccountConstraintEnable(localId: number, constraint: string, callback: AsyncCallback<boolean>): void + +Checks whether the specified constraint is enabled for an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ---------- | ---------------------- | ---- | ------------------------------ | + | localId | number | Yes | ID of the target OS account.| + | [constraint](#constraints) | string | Yes | Constraint specified.| + | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the constraint is enabled for the OS account, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + Check whether OS account 100 is forbidden to use Wi-Fi. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.isOsAccountConstraintEnable(localId, "constraint.wifi", (err, isConstraintEnabled)=>{ + console.log("isOsAccountConstraintEnable err:" + JSON.stringify(err)); + console.log("isOsAccountConstraintEnable isConstraintEnabled:" + isConstraintEnabled); + }); + ``` + +### isOsAccountConstraintEnable + +isOsAccountConstraintEnable(localId: number, constraint: string): Promise<boolean> + +Checks whether the specified constraint is enabled for an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ---------- | ------ | ---- | ---------------- | + | localId | number | Yes | ID of the target OS account.| + | [constraint](#constraints)| string | Yes | Constraint specified.| + +- Return value + + | Type | Description | + | :--------------- | :---------------------------------- | + | Promise<boolean> | Promise used to return the result. If the constraint is enabled for the OS account, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + Check whether OS account 100 is forbidden to use Wi-Fi. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.isOsAccountConstraintEnable(localId, "constraint.wifi").then((isConstraintEnabled) => { + console.log('isOsAccountConstraintEnable, isConstraintEnabled: ' + isConstraintEnabled); + }).catch((err) => { + console.log("isOsAccountConstraintEnable err: " + JSON.stringify(err)); + }); + ``` + +### isTestOsAccount + +isTestOsAccount(callback: AsyncCallback<boolean>): void + +Checks whether this OS account is a test account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------- | ---- | ------------------------------------------ | + | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the account is a test account, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.isTestOsAccount((err, isTest) => { + console.log("isTestOsAccount err: " + JSON.stringify(err)); + console.log('isTestOsAccount isTest: ' + isTest); + }); + ``` + +### isTestOsAccount + +isTestOsAccount(): Promise<boolean> + +Checks whether this OS account is a test account. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :--------------- | :---------------------------------- | + | Promise<boolean> | Promise used to return the result. If the account is a test account, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.isTestOsAccount().then((isTest) => { + console.log('isTestOsAccount, isTest: ' + isTest); + }).catch((err) => { + console.log("isTestOsAccount err: " + JSON.stringify(err)); + }); + ``` + +### isOsAccountVerified + +isOsAccountVerified(callback: AsyncCallback<boolean>): void + +Checks whether this OS account has been verified. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------- | ---- | ---------------------------------- | + | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.isOsAccountVerified((err, isVerified) => { + console.log("isOsAccountVerified err: " + JSON.stringify(err)); + console.log('isOsAccountVerified isVerified: ' + isVerified); + }); + ``` + +### isOsAccountVerified + +isOsAccountVerified(localId: number, callback: AsyncCallback<boolean>): void + +Checks whether an OS account has been verified. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------- | ---- | ---------------------------------- | + | localId | number | No | ID of the target OS account. | + | callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.isOsAccountVerified((err, isVerified) => { + console.log("isOsAccountVerified err: " + JSON.stringify(err)); + console.log('isOsAccountVerified isVerified: ' + isVerified); + }); + ``` + +### isOsAccountVerified + +isOsAccountVerified(localId: number?): Promise<boolean> + +Checks whether an OS account has been verified. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------- | ------ | ---- | ------------ | + | localId | number | No | ID of the target OS account.| + +- Return value + + | Type | Description | + | :--------------- | :---------------------------------- | + | Promise<boolean> | Promise used to return the result. If the OS account has been verified, **true** will be returned. Otherwise, **false** will be returned.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.isOsAccountVerified().then((isVerified) => { + console.log('isOsAccountVerified, isVerified: ' + isVerified); + }).catch((err) => { + console.log("isOsAccountVerified err: " + JSON.stringify(err)); + }); + ``` + +### removeOsAccount + +removeOsAccount(localId: number, callback: AsyncCallback<void>): void + +Removes an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ------------------- | ---- | ------------------------ | + | localId | number | Yes | ID of the OS account to remove. | + | callback | AsyncCallback<void> | Yes | Callback used to return the result.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + var createIocalId; + osAccountManager.createOsAccount("testAccountName", osaccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ + createIocalId = osAccountInfo.localId; + )}; + accountManager.removeOsAccount(createIocalId, (err)=>{ + console.log("removeOsAccount err:" + JSON.stringify(err)); + }); + ``` + +### removeOsAccount + +removeOsAccount(localId: number): Promise<void> + +Removes an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------- | ------ | ---- | ------------ | + | localId | number | Yes | ID of the OS account to remove.| + +- Return value + + | Type | Description | + | :------------ | :---------------------------------- | + | Promise<void> | Promise used to return the result.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + var createIocalId; + osAccountManager.createOsAccount("testAccountName", osaccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ + createIocalId = osAccountInfo.localId; + )}; + createIocalId = osAccount.localId; + accountManager.removeOsAccount(createIocalId).then(() => { + console.log('removeOsAccount Success'); + }).catch(() => { + console.log("removeOsAccount err: " + JSON.stringify(err)); + }); + ``` + +### setOsAccountConstraints + +setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean,callback: AsyncCallback<void>): void + +Sets or removes constraints for an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ----------- | ------------------- | ---- | ------------------------------- | + | localId | number | Yes | ID of the target OS account. | + | [constraints](constraints)| Array<string> | Yes | List of constraints to set or remove. | + | enable | boolean | Yes | Set or remove constraints. The value **true** means to set constraints, and **false** means to remove constraints. | + | callback | AsyncCallback<void> | Yes | Callback used to return the result.| + +- Example + + Disable Wi-Fi for OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.setOsAccountConstraints(localId, ["constraint.wifi"], true, (err)=>{ + console.log("setOsAccountConstraints err:" + JSON.stringify(err)); + }); + ``` + +### setOsAccountConstraints + +setOsAccountConstraints(localId: number, constraints: Array<string>, enable: boolean): Promise<void> + +Sets or removes constraints for an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ----------- | ------------- | ---- | ----------------------- | + | localId | number | Yes | ID of the target OS account. | + | [constraints](constraints)| Array<string> | Yes | List of constraints to set or remove.| + | enable | boolean | Yes | Set or remove constraints. The value **true** means to set constraints, and **false** means to remove constraints.| + +- Return value + + | Type | Description | + | :------------ | :---------------------------------- | + | Promise<void> | Promise used to return the result.| + +- Example + + Remove the constraint on Wi-Fi for OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.setOsAccountConstraints(localId, ["constraint.location.set"], false).then(() => { + console.log('setOsAccountConstraints Success'); + }).catch((err) => { + console.log("setOsAccountConstraints err: " + JSON.stringify(err)); + }); + ``` + +### setOsAccountName + +setOsAccountName(localId: number, localName: string, callback: AsyncCallback<void>): void + +Sets a name for an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | :-------- | ------------------- | ---- | ------------------------ | + | localId | number | Yes | ID of the target OS account. | + | localName | string | Yes | Account name to set. | + | callback | AsyncCallback<void> | Yes | Callback used to return the result.| + +- Example + + Set the name of OS account 100 to **demoName**. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + var newName = "demoName"; + accountManager.setOsAccountName(localId, newName, (err)=>{ + console.debug("setOsAccountName err:" + JSON.stringify(err)); + }); + ``` + +### setOsAccountName + +setOsAccountName(localId: number, localName: string): Promise<void> + +Sets a name for an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | --------- | ------ | ---- | ----------------------- | + | localId | number | Yes | ID of the target OS account. | + | localName | string | Yes | Account name to set.| + +- Return value + + | Type | Description | + | :------------ | :---------------------------------- | + | Promise<void> | Promise used to return the result.| + +- Example + + Set the name of OS account 100 to **demoName**. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + var nameLimit = "demoName"; + accountManager.setOsAccountName(localId, nameLimit).then(() => { + console.log('setOsAccountName Success'); + }).catch((err) => { + console.log("setOsAccountName err: " + JSON.stringify(err)); + }); + ``` + +### getCreatedOsAccountsCount + +getCreatedOsAccountsCount(callback: AsyncCallback<number>): void + +Obtains the number of OS accounts created. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | --------------------- | ---- | ------------------------------ | + | callback | AsyncCallback<number> | Yes | Callback used to return the number of OS accounts created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.getCreatedOsAccountsCount((err, accountCnt)=>{ + console.log("obtains the number of all os accounts created err:" + JSON.stringify(err)); + console.log("obtains the number of all os accounts created accountCnt:" + accountCnt); + }); + ``` + +### getCreatedOsAccountsCount + +getCreatedOsAccountsCount(): Promise<number> + +Obtains the number of OS accounts created. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<number> | Promise used to return the number of OS accounts created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.getCreatedOsAccountsCount().then((accountCnt) => { + console.log('getCreatedOsAccountsCount, accountCnt: ' + accountCnt); + }).catch((err) => { + console.log("getCreatedOsAccountsCount err: " + JSON.stringify(err)); + }); + ``` + +### getOsAccountLocalIdFromProcess + +getOsAccountLocalIdFromProcess(callback: AsyncCallback<number>): void + +Obtains the ID of the OS account to which the current process belongs. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | --------------------- | ---- | ----------------------------------------- | + | callback | AsyncCallback<number> | Yes | Callback used to return the account ID obtained.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.getOsAccountLocalIdFromProcess((err, accountID) => { + console.log("getOsAccountLocalIdFromProcess err: " + JSON.stringify(err)); + console.log('getOsAccountLocalIdFromProcess accountID: ' + accountID); + }); + ``` + +### getOsAccountLocalIdFromProcess + +getOsAccountLocalIdFromProcess(): Promise<number> + +Obtains the ID of the OS account to which the current process belongs. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<number> | Promise used to return the account ID obtained.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.getOsAccountLocalIdFromProcess().then((accountID) => { + console.log('getOsAccountLocalIdFromProcess, accountID: ' + accountID); + }).catch((err) => { + console.log("getOsAccountLocalIdFromProcess err: " + JSON.stringify(err)); + }); + ``` + +### getOsAccountLocalIdFromUid + +getOsAccountLocalIdFromUid(uid: number, callback: AsyncCallback<number>): void + +Obtains the OS account ID based on the process UID. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | --------------------- | ---- | --------------------------------------- | + | uid | number | Yes | Process UID.| + | callback | AsyncCallback<number> | Yes | Callback used to return the OS account ID obtained.| + +- Example + + Obtain the ID of the OS account whose process UID is **12345678**. + + ``` + const accountManager = account_osAccount.getAccountManager(); + let uid = 12345678; + accountManager.getOsAccountLocalIdFromUid(uid, (err, accountID) => { + console.log("getOsAccountLocalIdFromUid err: " + JSON.stringify(err)); + console.log('getOsAccountLocalIdFromUid: ' + accountID); + }); + ``` + +### getOsAccountLocalIdFromUid + +getOsAccountLocalIdFromUid(uid: number): Promise<number> + +Obtains the OS account ID based on the process UID. This method uses a promise to return the result. + +- Parameters + + | Name| Type | Mandatory| Description | + | ------ | ------ | ---- | ------------- | + | uid | number | Yes | Process UID.| + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<number> | Promise used to return the OS account ID obtained.| + +- Example + + Obtain the ID of the OS account whose process UID is **12345678**. + + ``` + const accountManager = account_osAccount.getAccountManager(); + let uid = 12345678; + accountManager.getOsAccountLocalIdFromUid(uid).then((accountID) => { + console.log('getOsAccountLocalIdFromUid: ' + accountID); + }).catch((err) => { + console.log("getOsAccountLocalIdFromUid err: " + JSON.stringify(err)); + }); + ``` + +### getOsAccountLocalIdFromDomain + +getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo, callback: AsyncCallback<number>): void + +Obtains the OS account ID based on domain account information. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | --------------------- | ---- | --------------------------------------- | + | domainInfo | [DomainAccountInfo](#domainaccountinfo) | Yes | Domain account information. | + | callback | AsyncCallback<number> | Yes | Callback used to return the ID of the OS account associated with the domain account.| + +- Example + + ``` + var domainInfo = {domain: "testDomain", accountName: "testAccountName"}; + const accountManager = account_osAccount.getAccountManager(); + accountManager.getOsAccountLocalIdFromDomain(domainInfo, (err, accountID) => { + console.log("getOsAccountLocalIdFromDomain: " + JSON.stringify(err)); + console.log('getOsAccountLocalIdFromDomain: ' + accountID); + }); + ``` + +### getOsAccountLocalIdFromDomain + +getOsAccountLocalIdFromDomain(domainInfo: DomainAccountInfo): Promise<number> + +Obtains the OS account ID based on domain account information. This method uses a promise to return the result. + +- Parameters + + | Name| Type | Mandatory| Description | + | ------ | ------ | ---- | ------------- | + | domainInfo | [DomainAccountInfo](#domainaccountinfo) | Yes | Domain account information.| + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<number> | Promise used to return the ID of the OS account associated with the domain account.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + var domainInfo = {domain: "testDomain", accountName: "testAccountName"}; + accountManager.getOsAccountLocalIdFromDomain(domainInfo).then((accountID) => { + console.log('getOsAccountLocalIdFromDomain: ' + accountID); + }).catch((err) => { + console.log("getOsAccountLocalIdFromDomain err: " + JSON.stringify(err)); + }); + ``` + +### queryMaxOsAccountNumber + +queryMaxOsAccountNumber(callback: AsyncCallback<number>): void + +Obtains the maximum number of OS accounts that can be created. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | --------------------- | ---- | ---------------------------------- | + | callback | AsyncCallback<number> | Yes | Callback used to return the maximum number of OS accounts that can be created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryMaxOsAccountNumber((err, maxCnt)=>{ + console.log("queryMaxOsAccountNumber err:" + JSON.stringify(err)); + console.log("queryMaxOsAccountNumber maxCnt:" + maxCnt); + }); + ``` + +### queryMaxOsAccountNumber + +queryMaxOsAccountNumber(): Promise<number> + +Obtains the maximum number of OS accounts that can be created. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<number> | Promise used to return the maximum number of OS accounts that can be created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryMaxOsAccountNumber().then((maxCnt) => { + console.log('queryMaxOsAccountNumber, maxCnt: ' + maxCnt); + }).catch((err) => { + console.log("queryMaxOsAccountNumber err: " + JSON.stringify(err)); + }); + ``` + +### getOsAccountAllConstraints + +getOsAccountAllConstraints(localId: number, callback: AsyncCallback<Array<string>>): void + +Obtains all constraints of an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------------- | ---- | ---------------------------------- | + | localId | number | Yes | ID of the target OS account. | + | callback | AsyncCallback<Array<string>> | Yes | Callback used to return all constraints obtained.| + +- Example + + Obtain all constraints of OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.getOsAccountAllConstraints(localId, (err, constraints)=>{ + console.log("getOsAccountAllConstraints err:" + JSON.stringify(err)); + console.log("getOsAccountAllConstraints:" + JSON.stringify(constraints)); + }); + ``` + +### getOsAccountAllConstraints + +getOsAccountAllConstraints(localId: number): Promise<Array<string>> + +Obtains all constraints of an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------- | ------ | ---- | ------------ | + | localId | number | Yes | ID of the target OS account.| + +- Return value + + | Type | Description | + | :--------------------- | :---------------------------------- | + | Promise<Array<string>> | Promise used to return the constraints obtained.| + +- Example + + Obtain all constraints of OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.getOsAccountAllConstraints(localId).then((constraints) => { + console.log("getOsAccountAllConstraints, constraints: " + constraints); + }).catch((err) => { + console.log("getOsAccountAllConstraints err: " + JSON.stringify(err)); + }); + ``` + +### queryAllCreatedOsAccounts + +queryAllCreatedOsAccounts(callback: AsyncCallback<Array<OsAccountInfo>>): void + +Obtains information about all the OS accounts created. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ----------------------------------- | ---- | -------------------------------- | + | callback | AsyncCallback<Array<[OsAccountInfo](#osaccountinfo)>> | Yes | Callback used to return information about OS accounts created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryAllCreatedOsAccounts((err, accountArr)=>{ + console.log("queryAllCreatedOsAccounts err:" + JSON.stringify(err)); + console.log("queryAllCreatedOsAccounts accountArr:" + JSON.stringify(accountArr)); + }); + ``` + +### queryAllCreatedOsAccounts + +queryAllCreatedOsAccounts(): Promise<Array<OsAccountInfo>> + +Obtains information about all the OS accounts created. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :---------------------------- | :---------------------------------- | + | Promise<Array<[OsAccountInfo](#osaccountinfo)>> | Promise used to return information about OS accounts created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryAllCreatedOsAccounts().then((accountArr) => { + console.log('queryAllCreatedOsAccounts, accountArr: ' + JSON.stringify(accountArr)); + }).catch((err) => { + console.log("queryAllCreatedOsAccounts err: " + JSON.stringify(err)); + }); + ``` + +### queryActivatedOsAccountIds + +queryActivatedOsAccountIds(callback: AsyncCallback<Array<number>>): void + +Obtains information about all activated OS accounts. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ----------------------------------- | ---- | -------------------------------- | + | callback | AsyncCallback<Array<number>> | Yes | Callback used to return information about activated OS accounts.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryActivatedOsAccountIds((err, idArray)=>{ + console.log("queryActivatedOsAccountIds err:" + JSON.stringify(err)); + console.log("queryActivatedOsAccountIds idArray length:" + idArray.length); + for(var i=0;i { + console.log('queryActivatedOsAccountIds, idArray: ' + idArray); + }).catch((err) => { + console.log("queryActivatedOsAccountIds err: " + JSON.stringify(err)); + }); + ``` + +### createOsAccount + +createOsAccount(localName: string, type: OsAccountType, callback: AsyncCallback<OsAccountInfo>): void + +Creates an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | :-------- | ---------------------------- | ---- | -------------------- | + | localName | string | Yes | Name of the OS account to create. | + | type | [OsAccountType](#osaccounttype) | Yes | Type of the OS account to create. | + | callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | Yes | Callback used to return the OS account created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.createOsAccount("testName", osaccount.OsAccountType.NORMAL, (err, osAccountInfo)=>{ + console.log("createOsAccount err:" + JSON.stringify(err)); + console.log("createOsAccount osAccountInfo:" + JSON.stringify(osAccountInfo)); + }); + ``` + +### createOsAccount + +createOsAccount(localName: string, type: OsAccountType): Promise<OsAccountInfo> + +Creates an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | --------- | ------------- | ---- | ---------------- | + | localName | string | Yes | Name of the OS account to create.| + | type | [OsAccountType](#osaccounttype) | Yes | Type of the OS account to create.| + +- Return value + + | Type | Description | + | :--------------------- | :---------------------------------- | + | Promise<[OsAccountInfo](#osaccountinfo)> | Promise used to return the OS account created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.createOsAccount("testAccountName", osaccount.OsAccountType.NORMAL).then((accountInfo) => { + console.log("createOsAccount, accountInfo: " + JSON.stringify(accountInfo)); + }).catch((err) => { + console.log("createOsAccount err: " + JSON.stringify(err)); + }); + ``` + +### createOsAccountForDomain + +createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo, callback: AsyncCallback<OsAccountInfo>): void + +Creates an OS account and associates it with the specified domain account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | :-------- | ---------------------------- | ---- | -------------------- | + | type | [OsAccountType](#osaccounttype) | Yes | Type of the OS account to create. | + | domainInfo | [DomainAccountInfo](#domainaccountinfo) | Yes | Domain account information. | + | callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | Yes | Callback used to return the OS account created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + var domainInfo = {domain: "testDomain", accountName: "testAccountName"}; + accountManager.createOsAccountForDomain(osaccount.OsAccountType.NORMAL, domainInfo, (err, osAccountInfo)=>{ + console.log("createOsAccountForDomain err:" + JSON.stringify(err)); + console.log("createOsAccountForDomain osAccountInfo:" + JSON.stringify(osAccountInfo)); + }); + ``` + +### createOsAccountForDomain + +createOsAccountForDomain(type: OsAccountType, domainInfo: DomainAccountInfo): Promise<OsAccountInfo> + +Creates an OS account and associates it with the specified domain account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | --------- | ------------- | ---- | ---------------- | + | type | [OsAccountType](#osaccounttype) | Yes | Type of the OS account to create.| + | domainInfo | [DomainAccountInfo](#domainaccountinfo) | Yes | Domain account information.| + +- Return value + + | Type | Description | + | :--------------------- | :---------------------------------- | + | Promise<[OsAccountInfo](#osaccountinfo)> | Promise used to return the OS account created.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + var domainInfo = {domain: "testDomain", accountName: "testAccountName"}; + accountManager.createOsAccountForDomain(osaccount.OsAccountType.NORMAL, domainInfo).then((accountInfo) => { + console.log("createOsAccountForDomain, account info: " + JSON.stringify(accountInfo)); + }).catch((err) => { + console.log("createOsAccountForDomain err: " + JSON.stringify(err)); + }); + ``` + +### queryCurrentOsAccount + +queryCurrentOsAccount(callback: AsyncCallback<OsAccountInfo>): void + +Obtains information about the OS account to which the current process belongs. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------------- | ---- | -------------------------- | + | callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | Yes | Callback used to return information about the OS account obtained.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryCurrentOsAccount((err, curAccountInfo)=>{ + console.log("queryCurrentOsAccount err:" + JSON.stringify(err)); + console.log("queryCurrentOsAccount curAccountInfo:" + JSON.stringify(curAccountInfo)); + }); + ``` + +### queryCurrentOsAccount + +queryCurrentOsAccount(): Promise<OsAccountInfo> + +Obtains information about the OS account to which the current process belongs. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :--------------------- | :---------------------------------- | + | Promise<[OsAccountInfo](#osaccountinfo)> | Promise used to return information about the OS account obtained.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.queryCurrentOsAccount().then((accountInfo) => { + console.log("queryCurrentOsAccount, accountInfo: " + JSON.stringify(accountInfo)); + }).catch((err) => { + console.log("queryCurrentOsAccount err: " + JSON.stringify(err)); + }); + ``` + +### queryOsAccountById + +queryOsAccountById(localId: number, callback: AsyncCallback<OsAccountInfo>): void + +Obtains information about an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------------- | ---- | -------------------------- | + | localId | number | Yes | ID of the target OS account.| + | callback | AsyncCallback<[OsAccountInfo](#osaccountinfo)> | Yes | Callback used to return the OS account information obtained.| + +- Example + + Query information about OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.queryOsAccountById(localId, (err, accountInfo)=>{ + console.log("queryOsAccountById err:" + JSON.stringify(err)); + console.log("queryOsAccountById accountInfo:" + JSON.stringify(accountInfo)); + }); + ``` + +### queryOsAccountById + +queryOsAccountById(localId: number): Promise<OsAccountInfo> + +Obtains information about an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------------- | ---- | -------------------------- | + | localId | number | Yes | ID of the target OS account.| + +- Return value + + | Type | Description | + | :--------------------- | :---------------------------------- | + | Promise<[OsAccountInfo](#osaccountinfo)> | Promise used to return the OS account information obtained.| + +- Example + + Query information about OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.queryOsAccountById(localId).then((accountInfo) => { + console.log("queryOsAccountById, accountInfo: " + JSON.stringify(accountInfo)); + }).catch((err) => { + console.log("queryOsAccountById err: " + JSON.stringify(err)); + }); + ``` + +### getOsAccountTypeFromProcess + +getOsAccountTypeFromProcess(callback: AsyncCallback<OsAccountType>): void + +Obtains the type of the OS account to which the current process belongs. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ---------------------------- | ---- | ---------------------------------------- | + | callback | AsyncCallback<[OsAccountType](#osaccounttype)> | Yes | Callback used to return the OS account type.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.getOsAccountTypeFromProcess((err, accountType) => { + console.log("getOsAccountTypeFromProcess err: " + JSON.stringify(err)); + console.log('getOsAccountTypeFromProcess accountType: ' + accountType); + }); + ``` + +### getOsAccountTypeFromProcess + +getOsAccountTypeFromProcess(): Promise<OsAccountType> + +Obtains the type of the OS account to which the current process belongs. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :--------------------- | :---------------------------------- | + | Promise<[OsAccountType](#osaccounttype)> | Promise used to return the OS account type.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.getOsAccountTypeFromProcess().then((accountType) => { + console.log('getOsAccountTypeFromProcess, accountType: ' + accountType); + }).catch((err) => { + console.log("getOsAccountTypeFromProcess err: " + JSON.stringify(err)); + }); + ``` + +### getDistributedVirtualDeviceId + +getDistributedVirtualDeviceId(callback: AsyncCallback<string>): void + +Obtains the ID of this distributed virtual device. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | --------------------- | ---- | ---------------------------- | + | callback | AsyncCallback<string> | Yes | Callback used to return the device ID obtained.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.getDistributedVirtualDeviceId((err, virtualID) => { + console.log("getDistributedVirtualDeviceId err: " + JSON.stringify(err)); + console.log('getDistributedVirtualDeviceId virtualID: ' + virtualID); + }); + ``` + +### getDistributedVirtualDeviceId + +getDistributedVirtualDeviceId(): Promise<string> + +Obtains the ID of this distributed virtual device. This method uses a promise to return the result. + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<string> | Promise used to return the device ID obtained.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + accountManager.getDistributedVirtualDeviceId().then((virtualID) => { + console.log('getDistributedVirtualDeviceId, virtualID: ' + virtualID); + }).catch((err) => { + console.log("getDistributedVirtualDeviceId err: " + JSON.stringify(err)); + }); + ``` + +### getOsAccountProfilePhoto + +getOsAccountProfilePhoto(localId: number, callback: AsyncCallback<string>): void + +Obtains the profile photo of an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | --------------------- | ---- | ------------------------ | + | localId | number | Yes | ID of the target OS account. | + | callback | AsyncCallback<string> | Yes | Callback used to return the profile photo obtained.| + +- Example + + Obtain the profile photo of OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.getOsAccountProfilePhoto(localId, (err, photo)=>{ + console.log("getOsAccountProfilePhoto err:" + JSON.stringify(err)); + console.log("get photo:" + photo + " by localId: " + localId); + }); + ``` + +### getOsAccountProfilePhoto + +getOsAccountProfilePhoto(localId: number): Promise<string> + +Obtains the profile photo of an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------- | ------ | ---- | ------------ | + | localId | number | Yes | ID of the target OS account.| + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<string> | Promise used to return the profile photo obtained.| + +- Example + + Obtain the profile photo of OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.getOsAccountProfilePhoto(localId).then((photo) => { + console.log("getOsAccountProfilePhoto: " + photo); + }).catch((err) => { + console.log("getOsAccountProfilePhoto err: " + JSON.stringify(err)); + }); + ``` + +### setOsAccountProfilePhoto + +setOsAccountProfilePhoto(localId: number, photo: string, callback: AsyncCallback<void>): void + +Sets a profile photo for an OS account. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | ------------------- | ---- | ------------------------ | + | localId | number | Yes | ID of the target OS account. | + | photo | string | Yes | Profile photo information. | + | callback | AsyncCallback<void> | Yes | Callback used to return the result.| + +- Example + + Set a profile photo for OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + var photo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA"+ + "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+ + "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+ + "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==" + osAccountManager.setOsAccountProfilePhoto(localId, photo, (err)=>{ + console.log("setOsAccountProfilePhoto err:" + JSON.stringify(err)); + }); + ``` + +### setOsAccountProfilePhoto + +setOsAccountProfilePhoto(localId: number, photo: string): Promise<void> + +Sets a profile photo for an OS account. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------- | ------ | ---- | ------------ | + | localId | number | Yes | ID of the target OS account.| + | photo | string | Yes | Profile photo information. | + +- Return value + + | Type | Description | + | :------------ | :---------------------------------- | + | Promise<void> | Promise used to return the result.| + +- Example + + Set a profile photo for OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + var photo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAAPCAYAAAA/I0V3AAAAAXNSR0IArs4c6QAAAARnQU1BAA"+ + "Cxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACwSURBVDhPvZLBDYMwDEV/ugsXRjAT0EHCOuFIBwkbdIRewi6unbiAyoGgSn1SFH85+Y"+ + "q/4ljARW62X+LHS8uIzjm4dXUYF+utzBikB52Jo5e5iEPKqpACk7R9NM2RvWm5tIkD2czLCUFNKLD6IjdMHFHDzws285MgGrT0xCtp3WOKHo"+ + "+7q0mP0DZW9pNmoEFUzrQjp5cCnaen2kSJXLFD8ghbXyZCMQf/8e8Ns1XVAG/XAgqKzVnJFAAAAABJRU5ErkJggg==" + accountManager.setOsAccountProfilePhoto(localId, photo).then(() => { + console.log("setOsAccountProfilePhoto success"); + }).catch((err) => { + console.log("setOsAccountProfilePhoto err: " + JSON.stringify(err)); + }); + ``` + +### getOsAccountLocalIdBySerialNumber + +getOsAccountLocalIdBySerialNumber(serialNumber: number, callback: AsyncCallback<number>): void + +Obtains the OS account ID based on the SN. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------------ | --------------------- | ---- | ------------------------------ | + | serialNumber | number | Yes | Account SN. | + | callback | AsyncCallback<number> | Yes | Callback used to return the OS account ID obtained.| + +- Example + + Obtain the ID of the OS account whose SN is 12345. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var serialNumber = 12345; + accountManager.getOsAccountLocalIdBySerialNumber(serialNumber, (err, localId)=>{ + console.log("ger localId err:" + JSON.stringify(err)); + console.log("get localId:" + localId + " by serialNumber: " + serialNumber); + }); + ``` + +### getOsAccountLocalIdBySerialNumber + +getOsAccountLocalIdBySerialNumber(serialNumber: number): Promise<number> + +Obtains the OS account ID based on the SN. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------------ | ------ | ---- | ---------- | + | serialNumber | number | Yes | Account SN.| + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<number> | Promise used to return the OS account ID obtained.| + +- Example + + Obtain the ID of the OS account whose SN is 12345. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var serialNumber = 12345; + accountManager.getOsAccountLocalIdBySerialNumber(serialNumber).then((localId) => { + console.log("getOsAccountLocalIdBySerialNumber localId: " + localId); + }).catch((err) => { + console.log("getOsAccountLocalIdBySerialNumber err: " + JSON.stringify(err)); + }); + ``` + +### getSerialNumberByOsAccountLocalId + +getSerialNumberByOsAccountLocalId(localId: number, callback: AsyncCallback<number>): void + +Obtains the SN of an OS account based on the account ID. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | --------------------- | ---- | ------------------------------ | + | localId | number | Yes | ID of the target OS account. | + | callback | AsyncCallback<number> | Yes | Callback used to return the account SN obtained.| + +- Example + + Obtain the SN of the OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.getSerialNumberByOsAccountLocalId(localId, (err, serialNumber)=>{ + console.log("ger serialNumber err:" + JSON.stringify(err)); + console.log("get serialNumber:" + serialNumber + " by localId: " + localId); + }); + ``` + +### getSerialNumberByOsAccountLocalId + +getSerialNumberByOsAccountLocalId(localId: number): Promise<number> + +Obtains the SN of an OS account based on the account ID. This method uses a promise to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | ------- | ------ | ---- | ------------ | + | localId | number | Yes | ID of the target OS account.| + +- Return value + + | Type | Description | + | :-------------- | :---------------------------------- | + | Promise<number> | Promise used to return the account SN obtained.| + +- Example + + Obtain the SN of the OS account 100. + + ``` + const accountManager = account_osAccount.getAccountManager(); + var localId = 100; + accountManager.getSerialNumberByOsAccountLocalId(localId).then((serialNumber) => { + console.log("getSerialNumberByOsAccountLocalId serialNumber: " + serialNumber); + }).catch((err) => { + console.log("getSerialNumberByOsAccountLocalId err: " + JSON.stringify(err)); + }); + ``` + +### on + +on(type: 'activate' | 'activating', name: string, callback: Callback<number>): void + +Subscribes to OS account changes. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | -------------------------- | ---- | ------------------------ | + | type | 'activate' \| 'activating' | Yes | Type of the event to subscribe to. The value **activate** means an event indicating that an OS account is activated, and **activating** means an event indicating that an OS account is being activated. | + | name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes.| + | callback | Callback<number> | Yes | Callback used to return the OS account ID and status changes.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + function onCallback(receiveLocalId){ + console.log("receive localId:" + receiveLocalId); + } + accountManager.on("activating", "osAccountOnOffNameA", onCallback); + ``` + +### off + +off(type: 'activate' | 'activating', name: string, callback?: Callback<number>): void + +Unsubscribes from the OS account changes. This method uses an asynchronous callback to return the result. + +- Parameters + + | Name | Type | Mandatory| Description | + | -------- | -------------------------- | ---- | ---------------------------- | + | type | 'activate' \| 'activating' | Yes | Type of the event to unsubscribe from. The value **activate** means an event indicating that an OS account is activated, and **activating** means an event indicating that an OS account is being activated. | + | name | string | Yes | Subscription name, which can be customized. The value cannot be empty or exceed 1024 bytes, and must be the same as the value passed by **on()**.| + | callback | Callback<number> | No | Callback used to return the OS account changes. By default, **0** is returned.| + +- Example + + ``` + const accountManager = account_osAccount.getAccountManager(); + function offCallback(){ + console.log("off enter") + } + accountManager.off("activating", "osAccountOnOffNameA", offCallback); + ``` + +## OsAccountInfo +Defines information about an OS account. +| Name | Type | Mandatory| Description | +| ----------------- | ---------------------------------- | ---- | ------------------------ | +| localId | number | Yes | ID of the target OS account. | +| localName | string | Yes | OS account name. | +| type | [OsAccountType](#osaccounttype) | Yes | OS account type. | +| [constraints](constraints) | Array<string> | No | Constraints on the OS account. | +| isVerified | boolean | Yes | Whether the OS account is verified. | +| photo | string | No | Profile photo of the OS account. | +| createTime | number | Yes | Time when the OS account was created. | +| lastLoginTime | number | No | Last login time of the OS account.| +| serialNumber | number | Yes | SN of the OS account. | +| isActived | boolean | Yes | Whether the OS account is activated. | +| isCreateCompleted | boolean | Yes | Whether the OS account information is complete. | +| distributedInfo | [distributedAccount.DistributedInfo](js-apis-distributed-account.md) | No | Distributed account information. | +| domainInfo | [DomainAccountInfo](#domainaccountinfo) | No | Domain account information. | + +## DomainAccountInfo +Defines the domain account information. +| Name | Type | Mandatory| Description | +| ----------------- | ---------------------------------- | ---- | ------------------------ | +| domain | string | Yes | Domain name. | +| accountName | string | Yes | Domain account name. | + +## Constraints + +| Constraint| Description| +| ----------------- | ------------------- | +| constraint.wifi | A user is not allowed to use Wi-Fi.| +| constraint.wifi.set | A user is not allowed to change Wi-Fi settings.| +| constraint.locale.set | A user is not allowed to change the device language.| +| constraint.app.accounts | A user is not allowed to add or delete app accounts.| +| constraint.apps.install | A user is not allowed to install apps.| +| constraint.apps.uninstall | A user is not allowed to uninstall apps.| +| constraint.location.shared | A user is not allowed to enable location sharing.| +| constraint.unknown.sources.install | A user is not allowed to install apps from unknown sources.| +| constraint.global.unknown.app.install | All users are not allowed to install apps from unknown sources.| +| constraint.bluetooth.set | A user is not allowed to configure Bluetooth.| +| constraint.bluetooth | The use of Bluetooth is prohibited on the device. +| constraint.bluetooth.share | Bluetooth sharing is prohibited.| +| constraint.usb.file.transfer | A user is not allowed to transfer files over USB.| +| constraint.credentials.set | A user is not allowed to configure user credentials.| +| constraint.os.account.remove | An admin user is not allowed to remove users or a non-admin user is not allowed to remove itself.| +| constraint.managed.profile.remove | The managed profiles of this user cannot be removed.| +| constraint.debug.features.use | A user is not allowed to enable or access debugging features.| +| constraint.vpn.set | A user is not allowed to configure a VPN.| +| constraint.date.time.set | A user is not allowed to set date, time, or time zone.| +| constraint.tethering.config | A user is not allowed to configure Tethering.| +| constraint.network.reset | A user is not allowed to reset network settings.| +| constraint.factory.reset | A user is not allowed to reset factory settings.| +| constraint.os.account.create | A user is not allowed to create users.| +| constraint.add.managed.profile | A user is not allowed to add managed profiles.| +| constraint.apps.verify.disable | A user is not allowed to disable app verification.| +| constraint.cell.broadcasts.set | A user is not allowed to configure cell broadcasts.| +| constraint.mobile.networks.set | A user is not allowed to configure radio networks.| +| constraint.control.apps | A user is not allowed to modify apps in **Settings** or the boot module.| +| constraint.physical.media | A user is not allowed to mount external physical media.| +| constraint.microphone | A user is not allowed to use microphones.| +| constraint.microphone.unmute | A user is not allowed to adjust the microphone volume.| +| constraint.volume.adjust | A user is not allowed to adjust the device's global volume.| +| constraint.calls.outgoing | A user is not allowed to make outgoing calls.| +| constraint.sms.use | A user is not allowed to send or receive SMS messages.| +| constraint.fun | A user is not allowed to have entertainment.| +| constraint.windows.create | Windows other than app windows cannot be created.| +| constraint.system.error.dialogs | Error dialogs for crashed or unresponsive apps are prohibited.| +| constraint.cross.profile.copy.paste | Pasting clipboard content to other users or profiles is prohibited.| +| constraint.beam.outgoing | A user is not allowed to use Near Field Communications (NFC) to transfer data from apps.| +| constraint.wallpaper | A user is not allowed to manage wallpapers.| +| constraint.safe.boot | A user is not allowed to reboot the device in safe boot mode.| +| constraint.parent.profile.app.linking | The apps in the parent profile are allowed to handle web links from the managed profile.| +| constraint.audio.record | Audio recording is prohibited.| +| constraint.camera.use | The use of cameras is prohibited.| +| constraint.os.account.background.run | Running in the background is prohibited.| +| constraint.data.roam | A user is not allowed to use cellular data when roaming.| +| constraint.os.account.set.icon | A user is not allowed to change their icon.| +| constraint.wallpaper.set | A user is not allowed to set a wallpaper.| +| constraint.oem.unlock | A user is not allowed to enable OEM unlock.| +| constraint.device.unmute | A user is not allowed to mute the device's global volume.| +| constraint.password.unified | The managed profile is not allowed to have unified lock screen challenge with the primary user.| +| constraint.autofill | A user is not allowed to use the autofill service.| +| constraint.content.capture | Capturing the content of a user's screen is prohibited.| +| constraint.content.suggestions | A user is not allowed to receive content suggestions.| +| constraint.os.account.start | User switching is blocked.| +| constraint.location.set | A user is not allowed to configure the location service.| +| constraint.airplane.mode.set | The airplane mode is prohibited on the device.| +| constraint.brightness.set | A user is not allowed to configure brightness.| +| constraint.share.into.profile | A user is not allowed to share files, images, or data from the primary user to the managed profile.| +| constraint.ambient.display | Ambient display is prohibited for the user.| +| constraint.screen.timeout.set | A user is not allowed to configure the screen off timeout.| +| constraint.print | A user is not allowed to print.| +| constraint.private.dns.set | A user is not allowed to configure a private domain name server (DNS).| diff --git a/en/device-dev/subsystems/subsys-data-relational-database-guide.md b/en/device-dev/subsystems/subsys-data-relational-database-guide.md index d668fc922079dfa5b38633d6c7a9c65a88351942..eeaa439df91494d306ebacd79fd40398d75ffea3 100644 --- a/en/device-dev/subsystems/subsys-data-relational-database-guide.md +++ b/en/device-dev/subsystems/subsys-data-relational-database-guide.md @@ -9,11 +9,11 @@ On the basis of the SQLite database, the RDB allows you to operate data with or The following table describes APIs available for creating and deleting an RDB store. -Table 1 APIs for creating and deleting an RDB store +**Table 1** APIs for creating and deleting an RDB store | Class| API| Description| | ---- | ---- | ---- | -| RdbStoreConfig | RdbStoreConfig(const std::string &path,
StorageMode storageMode = StorageMode::MODE_DISK,
bool readOnly = false,
const std::vector &encryptKey = std::vector(),
const std::string &journalMode = "",
const std::string &syncMode = "",
const std::string &databaseFileType = "",
const std::string &databaseFileSecurityLevel = "") | Configures an RDB store, including setting the name, storage mode, log mode, synchronization mode, and read-only mode, and encrypting the database.
  • **path**: path of the database.
  • **readOnly**: whether the database is read-only.
  • **storageMode**: storage mode.
  • **encryptKey**: key used for database encryption.
  • **journalMode**: database logging mode.
  • **syncMode**: data synchronization mode.
  • **databaseFileType**: database type.
  • **databaseFileSecurityLevel**: security level.
| +| RdbStoreConfig | RdbStoreConfig(const std::string &path,
StorageMode storageMode = StorageMode::MODE_DISK,
bool readOnly = false,
const std::vector &encryptKey = std::vector(),
const std::string &journalMode = "",
const std::string &syncMode = "",
const std::string &databaseFileType = "",
const std::string &databaseFileSecurityLevel = "") | Configures an RDB store, including setting the name, storage mode, log mode, synchronization mode, and read-only mode, and encrypting the RDB store.
- **path**: path of the database.
- **readOnly**: whether the database is read-only.
-  **storageMode**: storage mode.
- **encryptKey**: key used for database encryption.
- **journalMode**: database logging mode.
- **syncMode**: data synchronization mode.
- **databaseFileType**: database type.
- **databaseFileSecurityLevel**: security level. | | RdbOpenCallback | int OnCreate(RdbStore &rdbStore) | Called when an RDB store is created. You can add the method for initializing the table structure and add initialization data used by your application in the callback.| | RdbOpenCallback | int OnUpgrade(RdbStore &rdbStore, int currentVersion, int targetVersion) | Called when the RDB store is upgraded.| | RdbOpenCallback | int OnDowngrade(RdbStore &rdbStore, int currentVersion, int targetVersion) | Called when the RDB store is downgraded.| @@ -22,12 +22,12 @@ Table 1 APIs for creating and deleting an RDB store ### Encrypting an RDB Store -The RDB provides the database encryption capability. 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. +The RDB provides the database encryption capability. 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. -Table 2 API for changing the key +**Table 2** API for changing the key | Class| API| Description| | ---- | ---- | ---- | -| RdbStore | int ChangeEncryptKey(const std::vector &newKey) | Changes the encryption key for an RDB store.
Note: The encryption key can be changed only for an encrypted database.| +| RdbStore | int ChangeEncryptKey(const std::vector &newKey) | Changes the encryption key for an RDB store.
Note: The encryption key can be changed only for an encrypted RDB store.| ### Using Predicates @@ -36,7 +36,7 @@ The RDB provides **AbsRdbPredicates** for you to set database operation conditio - **RdbPredicates**: With this class, you do not need to write complex SQL statements. Instead, you can combine SQL statements simply by calling methods in this class, such as **equalTo**, **notEqualTo**, **groupBy**, **orderByAsc**, and **beginsWith**. - **RawRdbPredicates**: With this class, you can set **whereClause** and **whereArgs**, but cannot call methods such as **equalTo**. - Table 7 APIs for RDB predicates + **Table 3** APIs for RDB store predicates | Class| API| Description| | ---- | ---- | ---- | | RdbPredicates | AbsPredicates *EqualTo(std::string field, std::string value) | Sets the **AbsPredicates** to match the field that is equal to the specified value.| @@ -46,6 +46,9 @@ The RDB provides **AbsRdbPredicates** for you to set database operation conditio | RdbPredicates | AbsPredicates *OrderByAsc(std::string field) | Sets the **AbsPredicates** to match the column with values sorted in ascending order.| | RdbPredicates | void SetWhereClause(std::string whereClause) | Sets **whereClause**.| | RdbPredicates | void SetWhereArgs(std::vector\ whereArgs) | Sets **whereArgs**, which indicates the value of the placeholder in **whereClause**.| + | RdbPredicates | AbsRdbPredicates *InDevices(std::vector& devices) | Sets the **AbsPredicates** to specify the remote devices on the network with databases to be synchronized.| + | RdbPredicates | AbsRdbPredicates *InAllDevices() | Sets the **AbsPredicates** to connect to all remote devices on the network when synchronizing distributed databases.| + ### Managing Data in an RDB Store @@ -55,29 +58,29 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th The RDB provides an API for inserting data through **ValuesBucket** in a data table. If the data is added, the row number of the data inserted is returned; otherwise, **-1** is returned. - Table 3 API for inserting data to a data table + **Table 4** APIs for inserting data tables | Class| API| Description| | ---- | ---- | ---- | - | RdbStore | int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) | Inserts data based on the passed table name and data in **ValuesBucket**.
  • **table**: specifies the name of the target table.
  • **initialValues**: specifies the data, stored in **ValuesBucket**, to insert. A series of **put()** methods, such as **PutString(const std::string &columnName, const std::string &value)** and **PutDouble(const std::string &columnName, double value)**, are provided to add data to **ValuesBucket**.
| + | RdbStore | int Insert(int64_t &outRowId, const std::string &table, const ValuesBucket &initialValues) | Inserts data based on the passed table name and data in **ValuesBucket**.
- **table**: specifies the name of the target table.
- **initialValues**: specifies the data, stored in **ValuesBucket**, to insert. A series of **put()** methods, such as **PutString(const std::string &columnName, const std::string &value)** and **PutDouble(const std::string &columnName, double value)**, are provided to add data to **ValuesBucket**. | - Deleting data Call the **delete()** method to delete data meeting the conditions specified by **AbsRdbPredicates**. If the data is deleted, the row number of the deleted data is returned; otherwise, **0** is returned. - Table 5 API for deleting data + **Table 5** API for deleting data | Class| API| Description| | ---- | ---- | ---- | - | RdbStore | int Delete(int &deletedRows, const AbsRdbPredicates &predicates) | Deletes data.
  • **deletedRows**: specifies the number of rows to delete.
  • **predicates**: specifies the table name and conditions for deleting the data. **AbsRdbPredicates** has the following classes:
    • **RdbPredicates**: specifies delete conditions by calling its methods, such as **equalTo**.
    • **RawRdbPredicates**: specifies the table name, **whereClause** and **whereArgs** only.
| + | RdbStore | int Delete(int &deletedRows, const AbsRdbPredicates &predicates) | Deletes data.
- **deletedRows**: specifies the number of rows to delete.
- **predicates**: specifies the table name and conditions for deleting the data.
**AbsRdbPredicates** has the following classes:
- **RdbPredicates**: specifies update conditions by calling its methods, such as **equalTo**.
- **RawRdbPredicates**: specifies the table name, **whereClause** and **whereArgs** only. | - Updating data Call the **update()** method to modify data based on the passed data and the conditions specified by **AbsRdbPredicates**. If the data is updated, the row number of the updated data is returned; otherwise, **0** is returned. - Table 4 API for updating data + **Table 6** API for updating data | Class| API| Description| | ---- | ---- | ---- | - | RdbStore | int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates) | Updates the data that meets the conditions specified by predicates.
  • **changedRows**: specifies the number of rows to update.
  • **values**: specifies the new data stored in **ValuesBucket**.
  • **predicates**: specifies the table name and conditions for the update operation. **AbsRdbPredicates** has the following classes:
    • **RdbPredicates**: specifies update conditions by calling its methods, such as **equalTo**.
    • **RawRdbPredicates**: specifies the table name, **whereClause** and **whereArgs** only.
| + | RdbStore | int Update(int &changedRows, const ValuesBucket &values, const AbsRdbPredicates &predicates) | Updates the data that meets the conditions specified by predicates.
- **changedRows**: specifies the number of rows to update.
- **values**: specifies the new data stored in **ValuesBucket**.
- **predicates**: specifies the table name and conditions for the update operation. **AbsRdbPredicates** has the following classes:
- **RdbPredicates**: specifies update conditions by calling its methods, such as **equalTo**.
- **RawRdbPredicates**: specifies the table name, **whereClause** and **whereArgs** only. | - Querying data @@ -86,32 +89,75 @@ The RDB provides APIs for inserting, deleting, updating, and querying data in th - Call the **query()** method to query data based on the predicates, without passing any SQL statement. - Run the native SQL statement. - Table 6 APIs for querying data + **Table 7** APIs for querying data | Class| API| Description| | ---- | ---- | ---- | - | RdbStore | std::unique_ptr Query(const AbsRdbPredicates &predicates, const std::vector\ columns) | Queries data.
  • **predicates**: specifies the query conditions. **AbsRdbPredicates** has the following classes:
    • **RdbPredicates**: specifies the query conditions by calling its methods, such as **equalTo**.
    • **RawRdbPredicates**: specifies the table name, **whereClause**, and **whereArgs** only.
  • **columns**: specifies the number of columns returned.
| - | RdbStore | std::unique_ptr QuerySql(const std::string &sql, const std::vector\ &selectionArgs = std::vector\()) | Executes the native SQL statements to query data.
  • **sql**: specifies the native SQL statement.
  • **selectionArgs**: specifies the parameter values corresponding to the placeholders in the SQL statements. Set it to **null** if the **select** statement has no placeholder.
| + | RdbStore | std::unique_ptr Query(const AbsRdbPredicates &predicates, const std::vector\ columns) | Queries data.
- **predicates**: specifies the query conditions. **AbsRdbPredicates** has the following classes:
- **RdbPredicates**: specifies update conditions by calling its methods, such as **equalTo**.
- **RawRdbPredicates**: specifies the table name, **whereClause**, and **whereArgs** only.
- **columns**: specifies the number of columns returned. | + | RdbStore | std::unique_ptr QuerySql(const std::string &sql, const std::vector\ &selectionArgs = std::vector\()) | Executes the native SQL statements to query data.
- **sql**: specifies the native SQL statement.
- **selectionArgs**: specifies the parameter values corresponding to the placeholders in the SQL statements. Set it to **null** if the **select** statement has no placeholder. | ### Using the Result Set A result set can be regarded as rows 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**. - Table 8 APIs for using the result set - | Class| API| Description| - | ---- | ---- | ---- | - | ResultSet | int GoTo(int offset) | Moves the result set forwards or backwards by the specified offset relative to its current position.| - | ResultSet | int GoToRow(int position) | Moves the result set to the specified row.| - | ResultSet | int GoToNextRow() | Moves the result set to the next row.| - | ResultSet | int GoToPreviousRow() | Moves the result set to the previous row.| - | ResultSet | int IsStarted(bool &result) | Checks whether the result set has been moved.| - | ResultSet | int IsEnded(bool &result) | Checks whether the result set is moved after the last line.| - | ResultSet | int IsAtFirstRow(bool &result) | Checks whether the result set is located in the first row.| - | ResultSet | int IsAtLastRow(bool &result) | Checks whether the result set is located in the last row.| - | ResultSet | int GetRowCount(int &count) | Obtains the number of rows in the result set.| - | ResultSet | int GetColumnCount(int &count) | Obtains the number of columns in the result set.| - | ResultSet | int GetString(int columnIndex, std::string &value) | Obtains the values in the specified column of the current row, in strings.| - | ResultSet | int GetBlob(int columnIndex, std::vector\ &blob) | Obtains the values in the specified column of the current row, in a byte array.| - | ResultSet | int GetDouble(int columnIndex, double &value) | Obtains the values in the specified column of the current row, in double.| +**Table 8** APIs for using the result set +| Class| API| Description| +| ---- | ---- | ---- | +| ResultSet | int GoTo(int offset) | Moves the result set forwards or backwards by the specified offset relative to its current position.| +| ResultSet | int GoToRow(int position) | Moves the result set to the specified row.| +| ResultSet | int GoToNextRow() | Moves the result set to the next row.| +| ResultSet | int GoToPreviousRow() | Moves the result set to the previous row.| +| ResultSet | int IsStarted(bool &result) | Checks whether the result set has been moved.| +| ResultSet | int IsEnded(bool &result) | Checks whether the result set is moved after the last line.| +| ResultSet | int IsAtFirstRow(bool &result) | Checks whether the result set is located in the first row.| +| ResultSet | int IsAtLastRow(bool &result) | Checks whether the result set is located in the last row.| +| ResultSet | int GetRowCount(int &count) | Obtains the number of rows in the result set.| +| ResultSet | int GetColumnCount(int &count) | Obtains the number of columns in the result set.| +| ResultSet | int GetString(int columnIndex, std::string &value) | Obtains the values in the specified column of the current row, in strings.| +| ResultSet | int GetBlob(int columnIndex, std::vector\ &blob) | Obtains the values in the specified column of the current row, in a byte array.| +| ResultSet | int GetDouble(int columnIndex, double &value) | Obtains the values in the specified column of the current row, in double.| + +### Setting a List of Distributed Tables + +You can set a list of distributed tables for data operations across devices. + +**Table 9** API for setting a distributed table list +| Class| API| Description| +| ---- | ---- | ---- | +| RdbStore | bool SetDistributedTables(const std::vector& tables) | Sets a list of distributed tables.
- **tables**: specifies the names of the distributed tables to set. | + +### Obtaining the Distributed Table Name for a Remote Device + +When querying the RDB store of a remote device, you need to use the distributed table name. You can obtain the distributed table name of a remote device based on the local table name. + +**Table 10** API for obtaining the distributed table name of a remote device + +| Class| API| Description| +| ---- | ---- | ---- | +| RdbStore | std::string ObtainDistributedTableName(const std::string& device, const std::string& table) | Obtains the distributed table name of 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.
- **device**: specifies the ID of the remote device.
- **table**: specifies the name of the local table. | + +### Synchronizing Data Between Devices + +**Table 11** API for cross-device data synchronization + +| Class| API| Description| +| ---- | ---- | ---- | +| RdbStore | bool Sync(const SyncOption& option, const AbsRdbPredicates& predicate, const SyncCallback& callback) | Synchronizes data between devices.
- **option**: specifies synchronization options, which include the following:
**mode**: specifies how data is synchronized. The value **push** means to push data from the local device to the remote device; the value **pull** means to pull data from the remote device to the local device.
**isBlock**: specifies whether the invocation of this function is blocked.
- **callback**: specifies the callback used to return the result. | + +### Registering an RDB Store Observer + +**Table 12** API for registering an observer + +| Class| API| Description| +| ---- | ---- | ---- | +| RdbStore | bool Subscribe(const SubscribeOption& option, RdbStoreObserver *observer) | Registers an observer for this RDB store to subscribe to distributed data changes. When data in the RDB store changes, a callback will be invoked to return the data changes.
- **option**: specifies the subscription type.
- **observer**: specifies the observer of data changes in the RDB store. | + +### Unregistering an RDB Store Observer + +**Table 13** API for unregistering an observer + +| Class| API| Description| +| ---- | ---- | ---- | +| RdbStore | bool UnSubscribe(const SubscribeOption& option, RdbStoreObserver *observer) | Unregisters the observer of the specified type to unsubscribe from distributed data changes.
- **option**: specifies the subscription type to unregister.
- **observer**: specifies the observer to unregister. | ## Constraints @@ -121,7 +167,7 @@ None. 1. Create an RDB store. - a. Configure the RDB store attributes, including the database name, storage mode, and read-only mode. + a. Configure the RDB store attributes, including the RDB store name, storage mode, and read-only mode. b. Initialize the table structure and related data in the RDB store. @@ -155,6 +201,8 @@ None. b. Call the **insert()** method to insert data into the RDB store. + c. Create an RDB store. + The sample code is as follows: ``` ValuesBucket values; @@ -186,3 +234,76 @@ None. std::unique_ptr resultSet = store->Query(predicates, columns) resultSet.goToNextRow(); ``` + +4. Set the distributed tables to be synchronized. + + Call the **SetDistributedTables()** method to set the distributed tables to be synchronized. + + The sample code is as follows: + + ``` + store->SetDistributedTables("test"); + ``` + +5. Synchronize data. + + a. Set the data synchronization mode and block status. + + b. Constructs an **AbsPredicates** object to specify remote devices within the network to be synchronized. + + c. Call the **Sync()** method to synchronize data. + + The sample code is as follows: + + ``` + SyncOption option; + option.mode = PUSH; + option.isBlock = true; + AbsRdbPredicates predicate("test"); + predicate.InAllDevices(); + store->Sync(option, predicate, [] (const SyncResult& result) { + for (const auto& [device, status] : result) { + LogI("device=%s status=%d", device.c_str(), status); + } + }); + ``` + +6. Subscribe to distributed data. + + a. Override the **OnChange()** function. + + b. Define the distributed data subscription type. + + c. Call APIs to subscribe to or unsubscribe from distributed data. + + The sample code is as follows: + + ``` + class MyObserver : public RdbStoreObserver { + public: + void OnChange(const std::vector& devices) override { + for (const auto& device : devices) { + LOGI("device=%s data change", device.c_str()); + } + } + }; + + SubscribeOption option; + option.mode = SubscribeMode::REMOTE; + MyObserver observer; + store->Subscribe(option, &observer); // Subscribe to distributed data. + + store->UnSubscribe(option, &observer); // Unsubscribe from distributed data. + ``` + +7. Query data across devices. + + a. Obtain the distributed table name for a remote device based on the local table name. + + b. Run SQL statements to query data in the RDB store of the remote device. + + The sample code is as follows: + ``` + std::string tableName = store->ObtainDistributedTableName("123456789abcd", "test"); + auto resultSet = store->QuerySql("SELECT * from ?;", tableName); + ```