1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"), 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit AbilityKit 19 */ 20 21import type { AsyncCallback } from './@ohos.base'; 22import type wantConstant from './@ohos.app.ability.wantConstant'; 23 24/** 25 * This module provides the capability to authorize URI. 26 * 27 * @namespace uriPermissionManager 28 * @syscap SystemCapability.Ability.AbilityRuntime.Core 29 * @since 10 30 */ 31declare namespace uriPermissionManager { 32 /** 33 * Grant URI to another application 34 * 35 * @permission ohos.permission.PROXY_AUTHORIZATION_URI 36 * @param { string } uri - File URI. 37 * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, 38 * wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or 39 * wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION. 40 * @param { string } targetBundleName - Indicates the bundle name of authorization target. 41 * @param { AsyncCallback<number> } callback - the callback of grantUriPermission. 42 * @throws { BusinessError } 201 - Permission denied. 43 * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app. 44 * @throws { BusinessError } 401 - Parameter error. Possible causes: 45 * 1. Mandatory parameters are left unspecified; 46 * 2. Incorrect parameter types. 47 * @throws { BusinessError } 16000050 - Internal error. 48 * @throws { BusinessError } 16000058 - Invalid URI flag. 49 * @throws { BusinessError } 16000059 - Invalid URI type. 50 * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission. 51 * @syscap SystemCapability.Ability.AbilityRuntime.Core 52 * @systemapi hide this for inner system use. 53 * @since 10 54 */ 55 function grantUriPermission( 56 uri: string, 57 flag: wantConstant.Flags, 58 targetBundleName: string, 59 callback: AsyncCallback<number> 60 ): void; 61 62 /** 63 * Grant URI to another application 64 * 65 * @permission ohos.permission.PROXY_AUTHORIZATION_URI 66 * @param { string } uri - File URI. 67 * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, 68 * wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or 69 * wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION. 70 * @param { string } targetBundleName - Indicates the bundle name of authorization target. 71 * @returns { Promise<number> } - the promise returned by the function. 72 * @throws { BusinessError } 201 - Permission denied. 73 * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app. 74 * @throws { BusinessError } 401 - Parameter error. Possible causes: 75 * 1. Mandatory parameters are left unspecified; 76 * 2. Incorrect parameter types. 77 * @throws { BusinessError } 16000050 - Internal error. 78 * @throws { BusinessError } 16000058 - Invalid URI flag. 79 * @throws { BusinessError } 16000059 - Invalid URI type. 80 * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission. 81 * @syscap SystemCapability.Ability.AbilityRuntime.Core 82 * @systemapi hide this for inner system use. 83 * @since 10 84 */ 85 function grantUriPermission(uri: string, flag: wantConstant.Flags, targetBundleName: string): Promise<number>; 86 87 /** 88 * Grant URI to another application 89 * 90 * @permission ohos.permission.PROXY_AUTHORIZATION_URI 91 * @param { string } uri - File URI. 92 * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION, 93 * wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or 94 * wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION. 95 * @param { string } targetBundleName - Indicates the bundle name of authorization target. 96 * @param { number } appCloneIndex - Indicates the clone index of target application. 97 * @returns { Promise<void> } - the promise returned by the function. 98 * @throws { BusinessError } 201 - Permission denied. 99 * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app. 100 * @throws { BusinessError } 401 - Parameter error. Possible causes: 101 * 1. Mandatory parameters are left unspecified; 102 * 2. Incorrect parameter types. 103 * @throws { BusinessError } 16000050 - Internal error. 104 * @throws { BusinessError } 16000058 - Invalid URI flag. 105 * @throws { BusinessError } 16000059 - Invalid URI type. 106 * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission. 107 * @throws { BusinessError } 16000081 - Get target application info failed. 108 * @syscap SystemCapability.Ability.AbilityRuntime.Core 109 * @systemapi hide this for inner system use. 110 * @since 14 111 */ 112 function grantUriPermission(uri: string, flag: wantConstant.Flags, targetBundleName: string, appCloneIndex: number): Promise<void>; 113 114 /** 115 * Revoke URI from one application 116 * 117 * @permission ohos.permission.PROXY_AUTHORIZATION_URI 118 * @param { string } uri - File URI. 119 * @param { string } targetBundleName - Indicates the bundle name of authorization target. 120 * @param { AsyncCallback<number> } callback - the callback of revokeUriPermission. 121 * @throws { BusinessError } 201 - Permission denied. 122 * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app. 123 * @throws { BusinessError } 401 - Parameter error. Possible causes: 124 * 1. Mandatory parameters are left unspecified; 125 * 2. Incorrect parameter types. 126 * @throws { BusinessError } 16000050 - Internal error. 127 * @throws { BusinessError } 16000059 - Invalid URI type. 128 * @syscap SystemCapability.Ability.AbilityRuntime.Core 129 * @systemapi hide this for inner system use 130 * @since 10 131 */ 132 /** 133 * Revoke URI from one application 134 * 135 * @param { string } uri - File URI. 136 * @param { string } targetBundleName - Indicates the bundle name of authorization target. 137 * @param { AsyncCallback<number> } callback - the callback of revokeUriPermission. 138 * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app. 139 * @throws { BusinessError } 401 - Parameter error. Possible causes: 140 * 1. Mandatory parameters are left unspecified; 141 * 2. Incorrect parameter types. 142 * @throws { BusinessError } 16000050 - Internal error. 143 * @throws { BusinessError } 16000059 - Invalid URI type. 144 * @syscap SystemCapability.Ability.AbilityRuntime.Core 145 * @systemapi hide this for inner system use 146 * @since 12 147 */ 148 function revokeUriPermission(uri: string, targetBundleName: string, callback: AsyncCallback<number>): void; 149 150 /** 151 * Revoke URI from one application 152 * 153 * @permission ohos.permission.PROXY_AUTHORIZATION_URI 154 * @param { string } uri - File URI. 155 * @param { string } targetBundleName - Indicates the bundle name of authorization target. 156 * @returns { Promise<number> } - the promise returned by the function. 157 * @throws { BusinessError } 201 - Permission denied. 158 * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app. 159 * @throws { BusinessError } 401 - Parameter error. Possible causes: 160 * 1. Mandatory parameters are left unspecified; 161 * 2. Incorrect parameter types. 162 * @throws { BusinessError } 16000050 - Internal error. 163 * @throws { BusinessError } 16000059 - Invalid URI type. 164 * @syscap SystemCapability.Ability.AbilityRuntime.Core 165 * @systemapi hide this for inner system use 166 * @since 10 167 */ 168 /** 169 * Revoke URI from one application 170 * 171 * @param { string } uri - File URI. 172 * @param { string } targetBundleName - Indicates the bundle name of authorization target. 173 * @returns { Promise<number> } - the promise returned by the function. 174 * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app. 175 * @throws { BusinessError } 401 - Parameter error. Possible causes: 176 * 1. Mandatory parameters are left unspecified; 177 * 2. Incorrect parameter types. 178 * @throws { BusinessError } 16000050 - Internal error. 179 * @throws { BusinessError } 16000059 - Invalid URI type. 180 * @syscap SystemCapability.Ability.AbilityRuntime.Core 181 * @systemapi hide this for inner system use 182 * @since 12 183 */ 184 function revokeUriPermission(uri: string, targetBundleName: string): Promise<number>; 185 186 /** 187 * Revoke URI from one application 188 * 189 * @param { string } uri - File URI. 190 * @param { string } targetBundleName - Indicates the bundle name of authorization target. 191 * @param { number } appCloneIndex - Indicates the clone index of target application. 192 * @returns { Promise<void> } - the promise returned by the function. 193 * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app. 194 * @throws { BusinessError } 401 - Parameter error. Possible causes: 195 * 1. Mandatory parameters are left unspecified; 196 * 2. Incorrect parameter types. 197 * @throws { BusinessError } 16000050 - Internal error. 198 * @throws { BusinessError } 16000059 - Invalid URI type. 199 * @throws { BusinessError } 16000081 - Get target application info failed. 200 * @syscap SystemCapability.Ability.AbilityRuntime.Core 201 * @systemapi hide this for inner system use 202 * @since 14 203 */ 204 function revokeUriPermission(uri: string, targetBundleName: string, appCloneIndex: number): Promise<void>; 205} 206 207export default uriPermissionManager;