提交 e36641f3 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 94009e19
......@@ -13,6 +13,7 @@
- [@ohos.application.appManager](js-apis-appmanager.md)
- [@ohos.application.Configuration](js-apis-configuration.md)
- [@ohos.application.ConfigurationConstant](js-apis-configurationconstant.md)
- [@ohos.application.DataShareExtensionAbility](js-apis-application-DataShareExtensionAbility.md)
- [@ohos.ability.featureAbility](js-apis-featureAbility.md)
- [@ohos.application.formBindingData](js-apis-formbindingdata.md)
- [@ohos.application.FormExtension](js-apis-formextension.md)
......@@ -121,11 +122,14 @@
- Data Management
- [@ohos.data.dataAbility ](js-apis-data-ability.md)
- [@ohos.data.dataShare](js-apis-data-dataShare.md)
- [@ohos.data.dataSharePredicates](js-apis-data-dataSharePredicates.md)
- [@ohos.data.dataShareResultSet](js-apis-data-DataShareResultSet.md)
- [@ohos.data.distributedData](js-apis-distributed-data.md)
- [@ohos.data.distributedDataObject](js-apis-data-distributedobject.md)
- [@ohos.data.preferences](js-apis-data-preferences.md)
- [@ohos.data.rdb](js-apis-data-rdb.md)
- [@ohos.settings](js-apis-settings.md)
- [@ohos.data.ValuesBucket](js-apis-data-ValuesBucket.md)
- data/rdb/[resultSet](js-apis-data-resultset.md)
- File Management
......@@ -205,6 +209,7 @@
- [@ohos.power](js-apis-power.md)
- [@ohos.runningLock](js-apis-runninglock.md)
- [@ohos.sensor](js-apis-sensor.md)
- [@ohos.settings](js-apis-settings.md)
- [@ohos.systemParameter](js-apis-system-parameter.md)
- [@ohos.thermal](js-apis-thermal.md)
- [@ohos.update](js-apis-update.md)
......
# Data Share Extension Ability
**DataShareExtensionAbility** provides extension abilities for data share services based on the ExtensionAbility framework.
>**NOTE**
>
>The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
>The APIs provided by this module are system APIs.
>
>The APIs of this module can be used only in the stage model.
## Modules to Import
```ts
import DataShareExtensionAbility from '@ohos.application.DataShareExtensionAbility'
```
## onCreate
onCreate?(want: Want, callback: AsyncCallback&lt;void&gt;): void
Called to initialize service logic of the server when the DataShare client connects to the DataShareExtensionAbility server. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name| Type| Mandatory| Description|
| ----- | ------ | ------ | ------ |
| want | [Want](js-apis-application-Want.md#want) | Yes | **Want** information, including the ability name and bundle name.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback that returns no value.|
**Example**
```ts
import rdb from '@ohos.data.rdb';
let DB_NAME = "DB00.db";
let TBL_NAME = "TBL00";
let DDL_TBL_CREATE = "CREATE TABLE IF NOT EXISTS "
+ TBL_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, phoneNumber DOUBLE, isStudent BOOLEAN, Binary BINARY)";
let rdbStore;
export default class DataShareExtAbility extends DataShareExtensionAbility {
onCreate(want: Want, callback: AsyncCallback<void>) {
rdb.getRdbStore(this.context, {
name: DB_NAME
}, 1, function (err, data) {
console.log('getRdbStore done, data : ' + data);
rdbStore = data;
rdbStore.executeSql(DDL_TBL_CREATE, [], function (err) {
console.log('executeSql done, error message : ' + err);
});
if (callback) {
callback();
}
});
}
};
```
## getFileTypes
getFileTypes?(uri: string, mimeTypeFilter: string, callback: AsyncCallback&lt;Array&lt;string&gt;&gt;): void
Called by the server to obtain the Multipurpose Internet Mail Extensions (MIME) types supported by a file. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name | Type | Mandatory| Description |
| -------------- | ---------------------------------------- | ---- | ---------------------------------- |
| uri | string | Yes | URI of the file. |
| mimeTypeFilter | string | Yes | MIME types to match. |
| callback | AsyncCallback&lt;Array&lt;string&gt;&gt; | Yes | Callback invoked to return the MIME types obtained.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
getFileTypes(uri: string, mimeTypeFilter: string, callback: AsyncCallback<Array<string>>) {
let err = {"code":0};
let ret = new Array("type01", "type02", "type03");
callback(err, ret);
}
};
```
## openFile
openFile?(uri: string, mode: string, callback: AsyncCallback&lt;number&gt;): void
Called by the server to open a file. This method can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------------------------ |
| uri | string | Yes | URI of the file to open. |
| mode | string | Yes | File open mode, including read-only mode and read/write mode.|
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the file descriptor. |
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
openFile(uri: string, mode: string, callback: AsyncCallback<number>) {
let err = {"code":0};
let fd = 0;
callback(err,fd);
}
};
```
## insert
insert?(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback&lt;number&gt;): void
Called to insert data into the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name| Type| Mandatory| Description|
| ----- | ------ | ------ | ------ |
| uri |string | Yes | URI of the data to insert.|
| valueBucket |[ValuesBucket](js-apis-data-ValuesBucket.md#valuesbucket) | Yes| Data to insert.|
| callback |AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the index of the data inserted.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
insert(uri: string, valueBucket: ValuesBucket, callback: AsyncCallback<number>) {
if (value == null) {
console.info('invalid valueBuckets');
return;
}
rdbStore.insert(TBL_NAME, value, function (err, ret) {
console.info('callback ret:' + ret);
if (callback != undefined) {
callback(err, ret);
}
});
}
};
```
## update
update?(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback&lt;number&gt;): void
Called by the server to update data in the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name| Type| Mandatory| Description|
| ----- | ------ | ------ | ------ |
| uri | string | Yes | URI of the data to update.|
| predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for updating data.|
| valueBucket | [ValuesBucket](js-apis-data-ValuesBucket.md#valuesbucket) | Yes| New data.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback invoked to return the number of updated data records.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
update(uri: string, predicates: dataSharePredicates.DataSharePredicates, valueBucket: ValuesBucket, callback: AsyncCallback<number>) {
if (predicates == null || predicates == undefined) {
return;
}
rdbStore.update(TBL_NAME, value, predicates, function (err, ret) {
if (callback != undefined) {
callback(err, ret);
}
});
}
};
```
## delete
delete?(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback&lt;number&gt;): void
Called by the server to delete data from the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name | Type | Mandatory| Description |
| ---------- | ------------------------------------------------------------ | ---- | ---------------------------------- |
| uri | string | Yes | URI of the data to delete. |
| predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for deleting data. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of data records deleted.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
delete(uri: string, predicates: dataSharePredicates.DataSharePredicates, callback: AsyncCallback<number>) {
if (predicates == null || predicates == undefined) {
return;
}
rdbStore.delete(TBL_NAME, predicates, function (err, ret) {
if (callback != undefined) {
callback(err, ret);
}
});
}
};
```
## query
query?(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array&lt;string&gt;, callback: AsyncCallback&lt;Object&gt;): void
Called by the server to query data from the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name| Type| Mandatory| Description|
| ----- | ------ | ------ | ------ |
| uri | string | Yes | URI of the data to query.|
| predicates | [DataSharePredicates](js-apis-data-DataSharePredicates.md#datasharepredicates) | Yes | Filter criteria for querying data.|
| columns | Array&lt;string&gt; | Yes| Columns to query. If this parameter is empty, all columns will be queried.|
| callback | AsyncCallback&lt;Object&gt; | Yes| Callback invoked to return the result set.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
query(uri: string, predicates: dataSharePredicates.DataSharePredicates, columns: Array<string>, callback: AsyncCallback<Object>) {
if (predicates == null || predicates == undefined) {
return;
}
rdbStore.query(TBL_NAME, predicates, columns, function (err, resultSet) {
if (resultSet != undefined) {
console.info('resultSet.rowCount: ' + resultSet.rowCount);
}
if (callback != undefined) {
callback(err, resultSet);
}
});
}
};
```
## getType
getType?(uri: string, callback: AsyncCallback&lt;string&gt;): void
Called by the server to obtain the MIME type corresponding to the given URI. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name| Type| Mandatory| Description|
| ----- | ------ | ------ | ------ |
| uri | string | Yes | URI of the target data.|
| callback | AsyncCallback&lt;string&gt; | Yes| Callback invoked to return the MIME type obtained.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
getType(uri: string, callback: AsyncCallback<string>) {
let err = {"code":0};
let ret = "image";
callback(err, ret);
}
};
```
## BatchInsert
BatchInsert?(uri: string, valueBuckets: Array&lt;ValuesBucket&gt;, callback: AsyncCallback&lt;number&gt;): void
Called by the server to insert batch data into the database. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name | Type | Mandatory| Description |
| ------------ | ------------------------------------------------------------ | ---- | -------------------------------- |
| uri | string | Yes | URI of the data to insert. |
| valueBuckets | Array&lt;[ValuesBucket](js-apis-data-ValuesBucket.md#valuesbucket)&gt; | Yes | Data to insert. |
| callback | AsyncCallback&lt;number&gt; | Yes | Callback invoked to return the number of inserted data records.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
batchInsert(uri: string, valueBuckets: Array<ValuesBucket>, callback: AsyncCallback<number>) {
if (valueBuckets == null || valueBuckets.length == undefined) {
console.info('invalid valueBuckets');
return;
}
let resultNum = valueBuckets.length
valueBuckets.forEach(vb => {
rdbStore.insert(TBL_NAME, vb, function (err, ret) {
if (callback != undefined) {
callback(err, resultNum);
}
});
});
}
};
```
## normalizeUri
normalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
Called by the server to normalize the specified URI. This API can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ----------------------- |
| uri | string | Yes | [URI](js-apis-uri.md#uri) to normalize.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. If the operation is successful, the normalized URI is returned. Otherwise, **null** is returned.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
normalizeUri(uri: string, callback: AsyncCallback<string>) {
let err = {"code":0};
let ret = "normalize+" + uri;
callback(err, ret);
}
};
```
## denormalizeUri
denormalizeUri?(uri: string, callback: AsyncCallback&lt;string&gt;): void
Called by the server to denormalize the specified URI. This method can be overridden as required.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Provider
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ----------------------- |
| uri | string | Yes | [URI](js-apis-uri.md#uri) to denormalize.|
| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the result. If the operation is successful, the URI obtained is returned. If the URI passed in is returned, denormalization is not required. If denormalization is not supported, **null** is returned.|
**Example**
```ts
export default class DataShareExtAbility extends DataShareExtensionAbility {
denormalizeUri(uri: string, callback: AsyncCallback<string>) {
let err = {"code":0};
let ret = "denormalize+" + uri;
callback(err, ret);
}
};
```
# Data Share Result Set
The **DataShareResultSet** module provides methods for accessing the result set obtained from the database. You can access the values in the specified rows or the value of the specified data type.
>**NOTE**
>
>The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
import DataShareResultSet from '@ohos.data.DataShareResultSet';
```
## How to Use
You can call [query()](js-apis-data-dataShare.md#query) to obtain the **DataShareResultSet** object.
```ts
import dataShare from '@ohos.data.dataShare';
import dataSharePredicates from '@ohos.data.dataSharePredicates'
let dataShareHelper;
let uri = ("datashare:///com.samples.datasharetest.DataShare");
await dataShare.createDataShareHelper(this.context, uri, (err, data) => {
if (err != undefined) {
console.info("createDataShareHelper fail, error message : " + err);
} else {
console.info("createDataShareHelper end, data : " + data);
dataShareHelper = data;
}
});
let columns = ["*"];
let da = new dataSharePredicates.DataSharePredicates();
let resultSet;
da.equalTo("name", "ZhangSan");
dataShareHelper.query(uri, da, columns).then((data) => {
console.log("query end, data : " + data);
resultSet = data;
}).catch((err) => {
console.log("query fail, error message : " + err);
});
```
## Attributes
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
| Name | Type | Mandatory| Description |
| ----------- | ------------- | ---- | ------------------------ |
| columnNames | Array&lt;string&gt; | Yes | Names of all columns in the result set. |
| columnCount | number | Yes | Number of columns in the result set. |
| rowCount | number | Yes | Number of rows in the result set. |
| isClosed | boolean | Yes | Whether the result set is closed.|
## goToFirstRow
goToFirstRow(): boolean
Moves to the first row of the result set.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value**
| Type | Description |
| :------ | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```ts
let isGoTOFirstRow = resultSet.goToFirstRow();
console.info('resultSet.goToFirstRow: ' + isGoTOFirstRow);
```
## goToLastRow
goToLastRow(): boolean
Moves to the last row of the result set.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value**
| Type| Description|
| -------- | -------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```ts
let isGoToLastRow = resultSet.goToLastRow();
console.info('resultSet.goToLastRow: ' + isGoToLastRow);
```
## goToNextRow
goToNextRow(): boolean
Moves to the next row in the result set.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```ts
let isGoToNextRow = resultSet.goToNextRow();
console.info('resultSet.goToNextRow: ' + isGoToNextRow);
```
## goToPreviousRow
goToPreviousRow(): boolean
Moves to the previous row in the result set.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```ts
let isGoToPreviousRow = resultSet.goToPreviousRow();
console.info('resultSet.goToPreviousRow: ' + isGoToPreviousRow);
```
## goTo
goTo(offset:number): boolean
Moves based on the specified offset.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name**| **Type**| **Mandatory**| Description |
| ---------- | -------- | -------- | ------------------------------------------------------------ |
| offset | number | Yes | Offset relative to the current position. A negative value means to move backward, and a positive value means to move forward.|
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```ts
let goToNum = 1;
let isGoTo = resultSet.goTo(goToNum);
console.info('resultSet.goTo: ' + isGoTo);
```
## goToRow
goToRow(position: number): boolean
Moves to the specified row in the result set.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name**| **Type**| **Mandatory**| Description |
| ---------- | -------- | -------- | ------------------------ |
| position | number | Yes | Destination position to move.|
**Return value**
| Type | Description |
| ------- | --------------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
**Example**
```ts
let goToRowNum = 2
let isGoToRow = resultSet.goToRow(goToRowNum);
console.info('resultSet.goToRow: ' + isGoToRow);
```
## getBlob
getBlob(columnIndex: number): Uint8Array
Obtains the value in the specified column in the current row as a byte array.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name** | **Type**| **Mandatory**| Description |
| ----------- | -------- | -------- | ----------------------- |
| columnIndex | number | Yes | Index of the target column, starting from 0.|
**Return value**
| Type | Description |
| ---------- | -------------------------------- |
| Uint8Array | Value obtained.|
**Example**
```ts
let columnIndex = 1
let goToFirstRow = resultSet.goToFirstRow();
let getBlob = resultSet.getBlob(columnIndex);
console.info('resultSet.getBlob: ' + getBlob);
```
## getString
getString(columnIndex: number): *string*
Obtains the value in the specified column in the current row as a string.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name** | **Type**| **Mandatory**| Description |
| ----------- | -------- | -------- | ----------------------- |
| columnIndex | number | Yes | Index of the target column, starting from 0.|
**Return value**
| Type | Description |
| ------ | ---------------------------- |
| string | Value obtained.|
**Example**
```ts
let columnIndex = 1
let goToFirstRow = resultSet.goToFirstRow();
let getString = resultSet.getString(columnIndex);
console.info('resultSet.getString: ' + getString);
```
## getLong
getLong(columnIndex: number): number
Obtains the value in the specified column in the current row as a long integer.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name** | **Type**| **Mandatory**| Description |
| ----------- | -------- | -------- | ----------------------- |
| columnIndex | number | Yes | Index of the target column, starting from 0.|
**Return value**
| Type | Description |
| ------ | -------------------------- |
| number | Value obtained.|
**Example**
```ts
let columnIndex = 1
let goToFirstRow = resultSet.goToFirstRow();
let getLong = resultSet.getLong(columnIndex);
console.info('resultSet.getLong: ' + getLong);
```
## getDouble
getDouble(columnIndex: number): number
Obtains the value in the specified column in the current row as a double-precision floating-point number.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name** | **Type**| **Mandatory**| Description |
| ----------- | -------- | -------- | ----------------------- |
| columnIndex | number | Yes | Index of the target column, starting from 0.|
**Return value**
| Type | Description |
| ------ | ---------------------------- |
| number | Value obtained.|
**Example**
```ts
let columnIndex = 1
let goToFirstRow = resultSet.goToFirstRow();
let getDouble = resultSet.getDouble(columnIndex);
console.info('resultSet.getDouble: ' + getDouble);
```
## close
close(): void
Closes this result set.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Example**
```ts
resultSet.close();
```
## getColumnIndex
getColumnIndex(columnName: string): number
Obtains the column index based on the column name.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name**| **Type**| **Mandatory**| Description |
| ---------- | -------- | -------- | -------------------------- |
| columnName | string | Yes | Column name.|
**Return value**
| Type | Description |
| ------ | ------------------ |
| number | Column index obtained.|
**Example**
```ts
let ColumnName = "name"
let getColumnIndex = resultSet.getColumnIndex(ColumnName)
console.info('resultSet.getColumnIndex: ' + getColumnIndex);
```
## getColumnName
getColumnName(columnIndex: number): *string*
Obtains the column name based on the column index.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name** | **Type**| **Mandatory**| Description |
| ----------- | -------- | -------- | -------------------------- |
| columnIndex | number | Yes | Column index.|
**Return value**
| Type | Description |
| ------ | ------------------ |
| string | Column name obtained.|
**Example**
```ts
let columnIndex = 1
let getColumnName = resultSet.getColumnName(columnIndex)
console.info('resultSet.getColumnName: ' + getColumnName);
```
## getDataType
getDataType(columnIndex: number): DataType
Obtains the data type based on the specified column index.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
**Parameters**
| **Name** | **Type**| **Mandatory**| Description |
| ----------- | -------- | -------- | -------------------------- |
| columnIndex | number | Yes | Column index.|
**Return value**
| Type | Description |
| --------------------- | ------------------ |
| [DataType](#datatype) | Data type obtained.|
**Example**
```ts
let columnIndex = 1;
let getDataType = resultSet.getDataType(columnIndex);
console.info('resultSet.getDataType: ' + getDataType);
```
## DataType
Enumerates the data types.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
| Name | Value| Description |
| ----------- | ------ | -------------------- |
| TYPE_NULL | 0 | Null. |
| TYPE_LONG | 1 | Long integer. |
| TYPE_DOUBLE | 2 | Double-precision floating-point number.|
| TYPE_STRING | 3 | String.|
| TYPE_BLOB | 4 | Byte array.|
# Value Bucket
The **ValueBucket** holds data in key-value (KV) pairs. You can use it to insert data into a database.
>**Note**
>
>The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import
```ts
import { ValueType } from '@ohos.data.ValuesBucket';
import { ValuesBucket } from '@ohos.data.ValuesBucket';
```
## ValueType
Enumerates the value types allowed by the database.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
| Name | Description |
| ------- | -------------------- |
| number | The value is a number. |
| string | The value is a string.|
| boolean | The value is of Boolean type.|
## ValuesBucket
Holds a set of KV pairs.
**System capability**: SystemCapability.DistributedDataManager.DataShare.Core
| Name | Type | Mandatory| Description |
| ------------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| [key: string] | [ValueType](#valuetype)\| Uint8Array \| null | Yes | KV pairs in a **ValuesBucket**. The key is of the string type. The value can be a number, string, Boolean value, Unit8Array, or **null**.|
# Privacy Management
Provides APIs for privacy management, such as management of permission usage records.
The **PrivacyManager** module provides APIs for privacy management, such as management of permission usage records.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
>
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The APIs of this module are system APIs and cannot be called by third-party applications.
## Modules to Import
......@@ -19,7 +19,6 @@ import privacyManager from '@ohos.privacyManager';
addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: number, failCount: number): Promise&lt;number&gt;
Adds a permission usage record when an application protected by the permission is called by another service or application. This API uses a promise to return the result.
The permission usage record includes the application identity of the invoker, name of the permission used, and number of successful and failed accesses to the application.
**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
......@@ -41,10 +40,6 @@ The permission usage record includes the application identity of the invoker, na
| :------------ | :---------------------------------- |
| Promise&lt;number&gt; | Promise used to return the result. If **0** is returned, the record is added successfully. If **-1** is returned, the record fails to be added.|
```
```
**Example**
```js
......@@ -59,7 +54,6 @@ privacyManager.addPermissionUsedRecord(tokenID, "ohos.permission.PERMISSION_USED
addPermissionUsedRecord(tokenID: number, permissionName: string, successCount: number, failCount: number, callback: AsyncCallback&lt;number&gt;): void
Adds a permission usage record when an application protected by the permission is called by another service or application. This API uses an asynchronous callback to return the result.
The permission usage record includes the application identity of the invoker, name of the permission used, and number of successful and failed accesses to the application.
**Required permissions**: ohos.permission.PERMISSION_USED_STATS (available only to system applications)
......@@ -202,7 +196,7 @@ Represents the permission usage records of all applications.
## BundleUsedRecord
Represents the application access records of an application.
Represents the permission access records of an application.
**System capability**: SystemCapability.Security.AccessToken
......@@ -212,11 +206,11 @@ Represents the application access records of an application.
| isRemote | boolean | No | Whether the token ID belongs to a remote device. The default value is **false**.|
| deviceId | string | No | ID of the device hosting the target application. |
| bundleName | string | No | Bundle name of the target application.|
| permissionRecords | Array&lt;[PermissionUsedRecord](#PermissionUsedRecord)&gt; | No | Permission usage records of the specified application obtained. |
| permissionRecords | Array&lt;[PermissionUsedRecord](#PermissionUsedRecord)&gt; | No | Permission usage records of the target application. |
## PermissionUsedRecord
Represents the access records of a permission.
Represents the usage records of a permission.
**System capability**: SystemCapability.Security.AccessToken
......@@ -225,8 +219,8 @@ Represents the access records of a permission.
| permissionName | string | No | Name of the permission. |
| accessCount | number | No | Total number of times that the permission is accessed.|
| rejectCount | number | No | Total number of times that the access to the permission is rejected.|
| lastAccessTime | number | No | Last time when the permission was accessed, in ms.|
| lastRejectTime | number | No | Last time when the access to the permission was rejected, in ms.|
| lastAccessTime | number | No | Last time when the permission was accessed, accurate to ms.|
| lastRejectTime | number | No | Last time when the access to the permission was rejected, accurate to ms.|
| lastAccessDuration | number | No | Last access duration, in ms.|
| accessRecords | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt; | No | Access records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_SUMMARY**. By default, 10 records are provided. |
| rejectRecords | Array&lt;[UsedRecordDetail](#usedrecorddetail)&gt; | No | Rejected records. This parameter is valid only when **flag** is **FLAG_PERMISSION_USAGE_SUMMARY**. By default, 10 records are provided. |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册