From 5e0877df6cb63a11e651de8484a8066ef7f9257a Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Wed, 19 Jul 2023 16:24:12 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../apis/js-apis-uripermissionmanager.md | 123 +++++++++++++++--- 1 file changed, 107 insertions(+), 16 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-uripermissionmanager.md b/en/application-dev/reference/apis/js-apis-uripermissionmanager.md index c066b5d483..104ab731f9 100644 --- a/en/application-dev/reference/apis/js-apis-uripermissionmanager.md +++ b/en/application-dev/reference/apis/js-apis-uripermissionmanager.md @@ -17,12 +17,17 @@ import uriPermissionManager from '@ohos.application.uriPermissionManager'; ## uriPermissionManager.grantUriPermission -grantUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number, callback: AsyncCallback<number>): void +grantUriPermission(uri: string, flag: wantConstant.Flags, targetBundleName: string, callback: AsyncCallback<number>): void; Grants permission on the file of the specified URI to an application. This API uses an asynchronous callback to return the result. +By default, an application can authorize its own URIs to another application. If the application has the **ohos.permission.PROXY_AUTHORIZATION_URI** permission, there is no such restriction. +**System API**: This is a system API and cannot be called by third-party applications. + **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**Required permissions**: ohos.permission.PROXY_AUTHORIZATION_URI + **Parameters** | Name| Type| Mandatory| Description| @@ -32,26 +37,54 @@ Grants permission on the file of the specified URI to an application. This API u | targetBundleName | string | Yes| Bundle name of the application, to which the permission is granted.| | callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **0** is returned; otherwise, **-1** is returned.| +**Error codes** + +| ID| Error Message| +| ------- | -------------------------------- | +| 16000050 | Internal error. | +| 16000058 | Invalid URI flag. | +| 16000059 | Invalid URI type. | +| 16000060 | Sandbox application can not grant URI permission. | + +For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + **Example** ```js + import uriPermissionManager from '@ohos.application.uriPermissionManager'; import WantConstant from '@ohos.ability.wantConstant'; + import fileio from '@ohos.fileio'; + import fileUri from '@ohos.file.fileuri'; + let targetBundleName = 'com.example.test_case1' - let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10" + let path = "file://com.example.test_case1/data/storage/el2/base/haps/entry_test/files/newDir"; + fileio.mkdir(path, function (err) { + if (err) { + console.log("mkdir error"+err.message) + } else { + console.log("mkdir succeed") + } + }); + let uri = fileUri.getUriFromPath(path); uriPermissionManager.grantUriPermission(uri, WantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, targetBundleName, (result) => { - console.log("result.code = " + result.code) - }) + console.log("result.code = " + result.code) + }) ``` ## uriPermissionManager.grantUriPermission -grantUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number): Promise<number> +grantUriPermission(uri: string, flag: wantConstant.Flags, targetBundleName: string): Promise<number> Grants permission on the file of the specified URI to an application. This API uses a promise to return the result. +By default, an application can authorize its own URIs to another application. If the application has the **ohos.permission.PROXY_AUTHORIZATION_URI** permission, there is no such restriction. +**System API**: This is a system API and cannot be called by third-party applications. + **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**Required permissions**: ohos.permission.PROXY_AUTHORIZATION_URI + **Parameters** | Name| Type| Mandatory| Description| @@ -66,27 +99,56 @@ Grants permission on the file of the specified URI to an application. This API u | -------- | -------- | | Promise<number> | Promise used to return the result. If the operation is successful, **0** is returned; otherwise, **-1** is returned.| +**Error codes** + + | ID| Error Message| + | ------- | -------------------------------- | + | 16000050 | Internal error. | + | 16000058 | Invalid URI flag. | + | 16000059 | Invalid URI type. | + | 16000060 | Sandbox application can not grant URI permission. | + + For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + **Example** ```js + import uriPermissionManager from '@ohos.application.uriPermissionManager'; import WantConstant from '@ohos.ability.wantConstant'; + import fileio from '@ohos.fileio'; + import fileUri from '@ohos.file.fileuri'; + let targetBundleName = 'com.example.test_case1' - let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10" - uriPermissionManager.grantUriPermission(uri, wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, targetBundleName) - .then((data) => { + let path = "file://com.example.test_case1/data/storage/el2/base/haps/entry_test/files/newDir"; + + fileio.mkdir(path, function (err) { + if (err) { + console.log("mkdir error"+err.message) + } else { + console.log("mkdir succeed") + } + }); + let uri = fileUri.getUriFromPath(path); + uriPermissionManager.grantUriPermission(uri, WantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, targetBundleName) + .then((data) => { console.log('Verification succeeded.' + data) - }).catch((error) => { - console.log('Verification failed.'); + }).catch((error) => { + console.log('Verification failed.'); }) ``` ## uriPermissionManager.revokeUriPermission -revokeUriPermission(uri: string, accessTokenId: number, callback: AsyncCallback<number>): void +revokeUriPermission(uri: string, targetBundleName: string, callback: AsyncCallback<number>): void; Revokes the permission on the file of the specified URI from an application. This API uses an asynchronous callback to return the result. +By default, only the URIs obtained by the application itself or the URIs authorized by the application to other applications can be revoked. If the application has the **ohos.permission.PROXY_AUTHORIZATION_URI** permission, there is no such restriction. +**System API**: This is a system API and cannot be called by third-party applications. + **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**Required permissions**: ohos.permission.PROXY_AUTHORIZATION_URI + **Parameters** | Name| Type| Mandatory| Description| @@ -95,12 +157,23 @@ Revokes the permission on the file of the specified URI from an application. Thi | targetBundleName | string | Yes| Bundle name of the application, from which the permission is revoked.| | callback | AsyncCallback<number> | Yes| Callback invoked to return the result. If the operation is successful, **0** is returned; otherwise, **-1** is returned.| +**Error codes** + + | ID| Error Message| + | ------- | -------------------------------- | + | 16000050 | Internal error. | + | 16000059 | Invalid URI type. | + + For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + **Example** ```js + import uriPermissionManager from '@ohos.application.uriPermissionManager'; import WantConstant from '@ohos.ability.wantConstant'; - let targetBundleName = 'com.example.test_case1' - let URI = "fileshare:///com.samples.filesharetest.FileShare/person/10" + + let targetBundleName = 'com.example.test_case2' + let uri = "file://com.example.test_case1/data/storage/el2/base/haps/entry_test/files/newDir" uriPermissionManager.revokeUriPermission(uri, targetBundleName, (result) => { console.log("result.code = " + result.code) }) @@ -109,12 +182,19 @@ Revokes the permission on the file of the specified URI from an application. Thi ## uriPermissionManager.revokeUriPermission -revokeUriPermission(uri: string, flag: wantConstant.Flags, accessTokenId: number): Promise<number> +revokeUriPermission(uri: string, targetBundleName: string): Promise<number> Revokes the permission on the file of the specified URI from an application. This API uses a promise to return the result. + +By default, only the URIs obtained by the application itself or the URIs authorized by the application to other applications can be revoked. If the application has the **ohos.permission.PROXY_AUTHORIZATION_URI** permission, there is no such restriction. +**System API**: This is a system API and cannot be called by third-party applications. + **System capability**: SystemCapability.Ability.AbilityRuntime.Core +**Required permissions**: ohos.permission.PROXY_AUTHORIZATION_URI + + **Parameters** | Name| Type| Mandatory| Description| @@ -128,12 +208,23 @@ Revokes the permission on the file of the specified URI from an application. Thi | -------- | -------- | | Promise<number> | Promise used to return the result. If the operation is successful, **0** is returned; otherwise, **-1** is returned.| +**Error codes** + + | ID| Error Message| + | ------- | -------------------------------- | + | 16000050 | Internal error. | + | 16000059 | Invalid URI type. | + + For details about the error codes, see [Ability Error Codes](../errorcodes/errorcode-ability.md). + **Example** ```js + import uriPermissionManager from '@ohos.application.uriPermissionManager'; import WantConstant from '@ohos.ability.wantConstant'; - let targetBundleName = 'com.example.test_case1' - let uri = "fileshare:///com.samples.filesharetest.FileShare/person/10" + + let targetBundleName = 'com.example.test_case2' + let uri = "file://com.example.test_case1/data/storage/el2/base/haps/entry_test/files/newDir" uriPermissionManager.revokeUriPermission(uri, targetBundleName) .then((data) => { console.log('Verification succeeded.' + data) -- GitLab