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

!4961 #I57M8E完成

Merge pull request !4961 from Annie_wang/OpenHarmony-3.1-Release
......@@ -636,7 +636,7 @@ Sets the **RdbPredicates** to match the specified string.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| field | string | Yes| Column name in the database table.|
| value | string | Yes| Value to match the **RdbPredicates**.<br><br>Wildcards are supported. ***** indicates zero, one, or multiple digits or characters. **?** indicates a single digit or character.|
| value | string | Yes| Value to match the **RdbPredicates**.<br><br>Wildcards are supported. * indicates zero, one, or multiple digits or characters. ? indicates a single digit or character.|
**Return value**
| Type| Description|
......@@ -1390,7 +1390,7 @@ promise.then((resultSet) => {
executeSql(sql: string, bindArgs: Array&lt;ValueType&gt;, callback: AsyncCallback&lt;void&gt;):void
Runs the SQL statement that contains the specified parameters but does not return a value. This API uses a callback to return the execution result.
Runs the SQL statement that contains the specified parameters but does not return a value. This API uses a callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.RelationalStore.Core
......@@ -1555,9 +1555,9 @@ rdbStore.setDistributedTables(["EMPLOYEE"], function (err) {
console.info('setDistributedTables failed, err: ' + err)
return
}
console.info('setDistributedTables successful.')
console.info('setDistributedTables successfully.')
})
```
```
### setDistributedTables<sup>8+</sup>
......@@ -1582,7 +1582,7 @@ Sets a list of distributed tables. This API uses a promise to return the result.
```js
let promise = rdbStore.setDistributedTables(["EMPLOYEE"])
promise.then(() => {
console.info("setDistributedTables successful.")
console.info("setDistributedTables successfully.")
}).catch((err) => {
console.info("setDistributedTables failed, err: " + err)
})
......@@ -1610,7 +1610,7 @@ rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE", function (err, tableNa
console.info('obtainDistributedTableName failed, err: ' + err)
return
}
console.info('obtainDistributedTableName successful, tableName=.' + tableName)
console.info('obtainDistributedTableName successfully, tableName=.' + tableName)
})
```
......@@ -1638,7 +1638,7 @@ Obtains the distributed table name for a remote device based on the local table
```js
let promise = rdbStore.obtainDistributedTableName(deviceId, "EMPLOYEE")
promise.then((tableName) => {
console.info('obtainDistributedTableName successful, tableName=' + tableName)
console.info('obtainDistributedTableName successfully, tableName=' + tableName)
}).catch((err) => {
console.info('obtainDistributedTableName failed, err: ' + err)
})
......
......@@ -7,7 +7,7 @@ Lightweight storage provides applications with data processing capability and al
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
>
## Modules to Import
......@@ -22,15 +22,15 @@ import dataStorage from '@ohos.data.storage';
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| MAX_KEY_LENGTH | string | Yes| No| Maximum length of a key. It is 80 bytes.|
| MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value. It is 8192 bytes.|
| MAX_KEY_LENGTH | string | Yes| No| Maximum length of a key. It must be less than 80 bytes.|
| MAX_VALUE_LENGTH | string | Yes| No| Maximum length of a value. It must be less than 8192 bytes.|
## dataStorage.getStorageSync
getStorageSync(path: string): Storage
Reads the specified file and load its data to the **Storage** instance for data operations.
Reads the specified file and loads its data to the **Storage** instance for data operations.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
......
# User File Access and Management
>![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
>**NOTE**<br/>
>
>- The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>- The initial APIs of this module are supported since API version 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. Currently, these APIs can be called only by **filepicker**.
This module provides service APIs for accessing and managing user files. It interworks with the underlying file management services to implement media library and external card management, and provides capabilities for applications to query and create user files.
## Modules to Import
```js
......@@ -81,8 +83,8 @@ Obtains information about the second-level album or files in asynchronous mode.
- Parameters
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| path | string | Yes| URI of the directory to query.|
| type | string | Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| path | promise<string>| Yes| URI of the directory to query.|
| type | promise<string>| Yes| Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
- Return value
......@@ -128,8 +130,8 @@ Obtains information about the second-level album or files in asynchronous mode.
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| path | string | Yes | URI of the directory to query. |
| type | string | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| path | promise<string> | Yes | URI of the directory to query. |
| type | promise<string> | Yes | Type of the files to query. The file type can be **file**, **image**, **audio**, or **video**.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.<br>- &nbsp;**offset**: position to start the query. The value is a number.<br>- &nbsp;**count**: number of files to query.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
- Error
......@@ -156,7 +158,7 @@ Obtains information about the second-level album or files in asynchronous mode.
## filemanager.createFile
filemanager.createFile(path : string, filename : string, options? : {dev? : DevInfo}) : Promise&lt;string&gt;
createFile(path : string, filename : string, options? : {dev? : DevInfo}) : Promise&lt;string&gt;
Creates a file in the specified path in asynchronous mode. This API uses a promise to return the result.
......@@ -165,8 +167,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a promi
- Parameters
| Name| Type| Mandatory| Description|
| --- | --- | --- | -- |
| filename | string | Yes| Name of the file to create.|
| path | string | Yes| URI of the file to create.|
| filename | promise<string>| Yes| Name of the file to create.|
| path | promise<string>| Yes| URI of the file to create.|
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
- Return value
......@@ -209,8 +211,8 @@ Creates a file in the specified path in asynchronous mode. This API uses a callb
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ----------------------------- |
| filename | string | Yes | Name of the file to create. |
| path | string | Yes | URI of the file to create. |
| filename | promise<string> | Yes | Name of the file to create. |
| path | promise<string> | Yes | URI of the file to create. |
| options | Object | No| The options are as follows:<br>- &nbsp;**dev**: See [DevInfo](#devinfo). It is **dev = {name: "local"}** by default if not specified. Currently, only 'local' is supported.|
| callback | AsyncCallback&lt;[FileInfo](#fileinfo)[]&gt; | Yes | Callback invoked to return the file information obtained. |
......@@ -246,9 +248,9 @@ Defines the file information returned by **getRoot()** or **listFile()**.
| Name| Type| Readable| Writable| Description|
| --- | -- | -- | -- | -- |
| name | string | Yes| No| File name.|
| path | string | Yes| No| URI of the file.|
| type | string | Yes| No| File type.|
| name | promise<string>| Yes| No| File name.|
| path | promise<string>| Yes| No| URI of the file.|
| type | promise<string>| Yes| No| File type.|
| size | number | Yes| No| File size.|
| addedTime | number | Yes| No| Time when the file was scanned to the database.|
| modifiedTime | number | Yes| No| Time when the file was modified.|
......@@ -263,4 +265,4 @@ Defines the device type.
| Name| Type | Readable| Writable| Description |
| ------ | ------ | ---- | ---- | -------- |
| name | string | Yes | Yes | Device name.|
| name | promise<string>| Yes | Yes | Device name.|
# statfs
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> **NOTE**<br>
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
This module provides information related to the file system. It provides JS APIs to obtain the total number of bytes and the number of idle bytes of the file system.
## Modules to Import
```js
......@@ -11,11 +13,11 @@ import statfs from '@ohos.statfs';
## Guidelines
Before using this module to perform operations on a file or directory, obtain the absolute path of the file or directory. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Before using the APIs provided by this module to perform operations on a file or directory, obtain the path of the application sandbox. For details, see [getOrCreateLocalDir of the Context module](js-apis-Context.md).
Absolute file or directory path = Application directory + File name or directory name
Application sandbox path of a file or directory = Application directory + File name or directory name
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the absolute path of the file is as follows:
For example, if the application directory obtained by using **getOrCreateLocalDir** is **dir** and the file name is **xxx.txt**, the application sandbox path of the file is as follows:
```js
let path = dir + "xxx.txt";
......@@ -25,7 +27,7 @@ let path = dir + "xxx.txt";
getFreeBytes(path:string):Promise&lt;number&gt;
Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a promise to return the result.
Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -56,7 +58,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
getFreeBytes(path:string, callback:AsyncCallback&lt;number&gt;): void
Obtains the number of free bytes of the specified file system in asynchronous mode. This method uses a callback to return the result.
Obtains the number of free bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -79,7 +81,7 @@ Obtains the number of free bytes of the specified file system in asynchronous mo
getTotalBytes(path: string): Promise&lt;number&gt;
Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a promise to return the result.
Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......@@ -110,7 +112,7 @@ Obtains the total number of bytes of the specified file system in asynchronous m
getTotalBytes(path: string, callback: AsyncCallback&lt;number&gt;): void
Obtains the total number of bytes of the specified file system in asynchronous mode. This method uses a callback to return the result.
Obtains the total number of bytes of the specified file system in asynchronous mode. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.File.FileIO
......
# App Storage Statistics
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> **NOTE**<br/>
>
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - API version 9 is a canary release for trial use. The APIs of this version may be unstable.
> - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
This module provides functions to obtain storage statistics, including the space of built-in and plug-in memory cards, statistics of application data by type, and application data.
## Modules to Import
......@@ -130,7 +133,7 @@ Asynchronously obtains the available space of the specified volume. This API use
getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
Asynchronously obtains app information. This API uses a promise to return the result.
Asynchronously obtains application information. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
......@@ -138,13 +141,13 @@ Asynchronously obtains app information. This API uses a promise to return the re
| Name | Type | Mandatory| Description |
| ----------- | ------ | ---- | -------- |
| packageName | string | Yes | Bundle name of the app.|
| packageName | string | Yes | Bundle name of the application.|
- Return value
| Type | Description |
| ------------------------------------------ | -------------------------- |
| Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the app information.|
| Promise&lt;[Bundlestats](#bundlestats)&gt; | Promise used to return the application data obtained.|
- Example
......@@ -161,7 +164,7 @@ Asynchronously obtains app information. This API uses a promise to return the re
getBundleStats(packageName: string, callback: AsyncCallback&lt;BundleStats&gt;): void
Asynchronously obtains app information. This API uses a callback to return the result.
Asynchronously obtains application information. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
......@@ -169,8 +172,8 @@ Asynchronously obtains app information. This API uses a callback to return the r
| Name | Type | Mandatory| Description |
| -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
| packageName | string | Yes | Bundle name of the app.|
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback invoked to return the app information.|
| packageName | string | Yes | Bundle name of the application.|
| callback | callback:AsyncCallback&lt;[Bundlestats](#bundlestats)&gt; | Yes | Callback used to return the application information obtained.|
- Example
......@@ -186,10 +189,10 @@ Asynchronously obtains app information. This API uses a callback to return the r
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
### Attributes
### Attribute
| Name | Type | Description |
| --------- | ------ | -------------- |
| appSize<sup>9+</sup> | number | Size of the app. |
| cacheSize<sup>9+</sup> | number | Cache size of the app. |
| dataSize<sup>9+</sup> | number | Total data size of the app.|
| appSize<sup>9+</sup> | number | Size of the application. |
| cacheSize<sup>9+</sup> | number | Cache size of the application. |
| dataSize<sup>9+</sup> | number | Total data size of the application.|
......@@ -68,7 +68,7 @@ Sets the value in the cache based on the specified key.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| key | string | Yes| Key of the data to set.|
| value | string | Yes| New value to set. The maximum length is 128 bytes.|
| value | string | Yes| New value to set. The length must be less than 128 bytes.|
| success | Function | No| Called when **storage.set()** is successful.|
| fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.|
| complete | Function | No| Called when **storage.set()** is complete.|
......
# Volume Management
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/>
> **NOTE**<br>
>
> - The initial APIs of this module are supported since API version 9.
> - API version 9 is a canary release for trial use. The APIs of this version may be unstable.
> - API version 9 is a canary version for trial use. The APIs of this version may be unstable.
> - The APIs of this module are system APIs and cannot be called by third-party applications.
This module provides APIs to implement volume and disk management, including obtaining volume information, mounting and unmounting volumes, partitioning disks, and formatting volumes.
## Modules to Import
......@@ -15,7 +18,7 @@ import volumemanager from "@ohos.volumeManager";
getAllVolumes(): Promise&lt;Array&lt;Volume&gt;&gt;
Asynchronously obtains information about all available volumes. This method uses a promise to return the result.
Asynchronously obtains information about all available volumes. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume
......@@ -37,7 +40,7 @@ Asynchronously obtains information about all available volumes. This method uses
getAllVolumes(callback: AsyncCallback&lt;Array&lt;Volume&gt;&gt;): void
Asynchronously obtains information about all available volumes. This method uses a callback to return the result.
Asynchronously obtains information about all available volumes. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume
......@@ -61,7 +64,7 @@ Asynchronously obtains information about all available volumes. This method uses
mount(volumeId: string): Promise&lt;boolean&gt;
Asynchronously mounts a volume. This method uses a promise to return the result.
Asynchronously mounts a volume. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume
......@@ -90,7 +93,7 @@ Asynchronously mounts a volume. This method uses a promise to return the result.
mount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
Asynchronously obtains the available space of the specified volume. This method uses a callback to return the result.
Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume
......@@ -114,7 +117,7 @@ Asynchronously obtains the available space of the specified volume. This method
unmount(volumeId: string): Promise&lt;boolean&gt;
Asynchronously unmounts a volume. This method uses a promise to return the result.
Asynchronously unmounts a volume. This API uses a promise to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume
......@@ -143,7 +146,7 @@ Asynchronously unmounts a volume. This method uses a promise to return the resul
unmount(volumeId: string, callback:AsyncCallback&lt;boolean&gt;):void
Asynchronously unmounts a volume. This method uses a callback to return the result.
Asynchronously unmounts a volume. This API uses a callback to return the result.
**System capability**: SystemCapability.FileManagement.StorageService.Volume
......
# Access Control Development
## Scenario
## When to Use
In this example, the app requires the **ohos.permission.PERMISSION1** and **ohos.permission.PERMISSION2** permissions to implement core functions.
......@@ -26,7 +26,7 @@ The table below lists only the API used in this guide. For more information, see
### config.json
Declare the permissions required by the app one by one in the **config.json** file. The app cannot obtain a permission if it is not declared in the **config.json** file.
Declare the permissions required by the app one by one in the **config.json** file. The app can obtain permissions that have been declared in the **config.json** file.
**Description of config.json**
......@@ -107,7 +107,7 @@ In addition to declaring all the permissions in the **config.json** file, you mu
After the permissions are declared, the system grants the system_grant permission during the installation of the app. The user_grant permission must be authorized by the user.
Therefore, before invoking the API protected by the **ohos.permission.PERMISSION2 permission**, the app needs to verify whether it has the permission.
Therefore, before allowing the app to call the API protected by the **ohos.permission.PERMISSION2** permission, the system needs to verify whether the app has the permission to do so.
If the verification result indicates that the app has the permission, the app can access the target API. Otherwise, the app needs to request user authorization and then proceeds based on the authorization result. For details, see [Access Control Overview](accesstoken-overview.md).
......@@ -119,34 +119,26 @@ If the verification result indicates that the app has the permission, the app ca
The procedure is as follows:
1. Obtain the caller's identity tokenId.
2. Determine the permission to be verified. In this example, the permission is **permissionNameUser**.
3. Call **verifyAccessToken** to verify the permissions of the caller.
4. Proceed based on the permission verification result.
1. Obtain the ability context.
2. Call **requestPermissionsFromUser** to verify whether the app has required permissions.
3. Proceed based on the permission verification result.
```js
import {describe, beforeEach, afterEach, it, expect} from 'deccjsunit/index'
import abilityAccessCtrl from '@ohos.abilityAccessCtrl'
import bundle from '@ohos.bundle'
async requestPermission() {
var permissionNameUser = "ohos.permission.PERMISSION2";
var bundleFlag = 0;
var tokenID = undefined;
var userID = 100;
var appInfo = await bundle.getApplicationInfo('ohos.acts.security.access_token.normal', bundleFlag, userID);
tokenID = appInfo.accessTokenId;
console.log("AccessTokenTest accessTokenId:" + appInfo.accessTokenId + ", name:" + appInfo.name
+ ", bundleName:" + appInfo.bundleName)
var atManager = abilityAccessCtrl.createAtManager();
var result = await atManager.verifyAccessToken(tokenID, permissionNameUser);
if (result == abilityAccessCtrl.GrantStatus.PERMISSION_GRANTED) {
// Execute the operation.
} else {
// Apply for dynamic user authorization using requestPermissionsFromUser.
}
// OnWindowStageCreate lifecycle of the ability
onWindowStageCreate() {
var context = this.context
let array:Array<string> = ["ohos.permission.PERMISSION2"];
// requestPermissionsFromUser determines whether to invoke a pop-up window based on the permission authorization status.
context.requestPermissionsFromUser(array).then(function(data) {
console.log("data type:" + typeof(data));
console.log("data:" + data);
console.log("data permissions:" + data.permissions);
console.log("data result:" + data.authResults);
}, (err) => {
console.error('Failed to start ability', err.code);
});
}
```
> ![icon-note.gif](../public_sys-resources/icon-note.gif)**NOTE**<br/>
> For details about how to use **requestPermissionsFromUser**, see [API Reference] (../reference/apis/js-apis-ability-context.md#abilitycontextrequestpermissionsfromuser).
> **NOTE**<br>
> For details about how to use **requestPermissionsFromUser**, see [API Reference](../reference/apis/js-apis-ability-context.md#abilitycontextrequestpermissionsfromuser).
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册