• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 arkts {'1.1':'10', '1.2':'20'}
30 * @arkts 1.1&1.2
31 */
32declare namespace uriPermissionManager {
33  /**
34   * Grant URI to another application
35   *
36   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
37   * @param { string } uri - File URI.
38   * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
39   *                                      wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or
40   *                                      wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION.
41   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
42   * @param { AsyncCallback<number> } callback - the callback of grantUriPermission.
43   * @throws { BusinessError } 201 - Permission denied.
44   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
45   * @throws { BusinessError } 401 - Parameter error. Possible causes:
46   *                                 1. Mandatory parameters are left unspecified;
47   *                                 2. Incorrect parameter types.
48   * @throws { BusinessError } 16000050 - Internal error.
49   * @throws { BusinessError } 16000058 - Invalid URI flag.
50   * @throws { BusinessError } 16000059 - Invalid URI type.
51   * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission.
52   * @syscap SystemCapability.Ability.AbilityRuntime.Core
53   * @systemapi hide this for inner system use.
54   * @since 10
55   */
56  /**
57   * Grant URI to another application
58   *
59   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
60   * @param { string } uri - File URI.
61   * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
62   *                                      wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or
63   *                                      wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION.
64   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
65   * @param { AsyncCallback<number> } callback - the callback of grantUriPermission.
66   * @throws { BusinessError } 201 - Permission denied.
67   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
68   * @throws { BusinessError } 401 - Parameter error. Possible causes:
69   *                                 1. Mandatory parameters are left unspecified;
70   *                                 2. Incorrect parameter types.
71   * @throws { BusinessError } 801 - Capability not supported.
72   * @throws { BusinessError } 16000050 - Internal error.
73   * @throws { BusinessError } 16000058 - Invalid URI flag.
74   * @throws { BusinessError } 16000059 - Invalid URI type.
75   * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission.
76   * @syscap SystemCapability.Ability.AbilityRuntime.Core
77   * @systemapi hide this for inner system use.
78   * @since arkts {'1.1':'19', '1.2':'20'}
79   * @arkts 1.1&1.2
80   */
81  function grantUriPermission(
82    uri: string,
83    flag: wantConstant.Flags,
84    targetBundleName: string,
85    callback: AsyncCallback<number>
86  ): void;
87
88  /**
89   * Grant URI to another application
90   *
91   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
92   * @param { string } uri - File URI.
93   * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
94   *                                      wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or
95   *                                      wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION.
96   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
97   * @returns { Promise<number> } - 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   * @syscap SystemCapability.Ability.AbilityRuntime.Core
108   * @systemapi hide this for inner system use.
109   * @since 10
110   */
111  /**
112   * Grant URI to another application
113   *
114   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
115   * @param { string } uri - File URI.
116   * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
117   *                                      wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or
118   *                                      wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION.
119   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
120   * @returns { Promise<number> } - the promise returned by the function.
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 } 801 - Capability not supported.
127   * @throws { BusinessError } 16000050 - Internal error.
128   * @throws { BusinessError } 16000058 - Invalid URI flag.
129   * @throws { BusinessError } 16000059 - Invalid URI type.
130   * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission.
131   * @syscap SystemCapability.Ability.AbilityRuntime.Core
132   * @systemapi hide this for inner system use.
133   * @since arkts {'1.1':'19', '1.2':'20'}
134   * @arkts 1.1&1.2
135   */
136  function grantUriPermission(uri: string, flag: wantConstant.Flags, targetBundleName: string): Promise<number>;
137
138  /**
139   * Grant URI to another application
140   *
141   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
142   * @param { string } uri - File URI.
143   * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
144   *                                      wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or
145   *                                      wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION.
146   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
147   * @param { number } appCloneIndex - Indicates the clone index of target application.
148   * @returns { Promise<void> } - the promise returned by the function.
149   * @throws { BusinessError } 201 - Permission denied.
150   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
151   * @throws { BusinessError } 401 - Parameter error. Possible causes:
152   *                                 1. Mandatory parameters are left unspecified;
153   *                                 2. Incorrect parameter types.
154   * @throws { BusinessError } 16000050 - Internal error.
155   * @throws { BusinessError } 16000058 - Invalid URI flag.
156   * @throws { BusinessError } 16000059 - Invalid URI type.
157   * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission.
158   * @throws { BusinessError } 16000081 - Failed to obtain the target application information.
159   * @syscap SystemCapability.Ability.AbilityRuntime.Core
160   * @systemapi hide this for inner system use.
161   * @since 14
162   */
163  /**
164   * Grant URI to another application
165   *
166   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
167   * @param { string } uri - File URI.
168   * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
169   *                                      wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or
170   *                                      wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION.
171   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
172   * @param { number } appCloneIndex - Indicates the clone index of target application.
173   * @returns { Promise<void> } - the promise returned by the function.
174   * @throws { BusinessError } 201 - Permission denied.
175   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
176   * @throws { BusinessError } 401 - Parameter error. Possible causes:
177   *                                 1. Mandatory parameters are left unspecified;
178   *                                 2. Incorrect parameter types.
179   * @throws { BusinessError } 801 - Capability not supported.
180   * @throws { BusinessError } 16000050 - Internal error.
181   * @throws { BusinessError } 16000058 - Invalid URI flag.
182   * @throws { BusinessError } 16000059 - Invalid URI type.
183   * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission.
184   * @throws { BusinessError } 16000081 - Failed to obtain the target application information.
185   * @syscap SystemCapability.Ability.AbilityRuntime.Core
186   * @systemapi hide this for inner system use.
187   * @since arkts {'1.1':'19', '1.2':'20'}
188   * @arkts 1.1&1.2
189   */
190  function grantUriPermission(uri: string, flag: wantConstant.Flags, targetBundleName: string, appCloneIndex: number): Promise<void>;
191
192  /**
193   * Revoke URI from one application
194   *
195   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
196   * @param { string } uri - File URI.
197   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
198   * @param { AsyncCallback<number> } callback - the callback of revokeUriPermission.
199   * @throws { BusinessError } 201 - Permission denied.
200   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
201   * @throws { BusinessError } 401 - Parameter error. Possible causes:
202   *                                 1. Mandatory parameters are left unspecified;
203   *                                 2. Incorrect parameter types.
204   * @throws { BusinessError } 16000050 - Internal error.
205   * @throws { BusinessError } 16000059 - Invalid URI type.
206   * @syscap SystemCapability.Ability.AbilityRuntime.Core
207   * @systemapi hide this for inner system use
208   * @since 10
209   */
210  /**
211   * Revoke URI from one application
212   *
213   * @param { string } uri - File URI.
214   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
215   * @param { AsyncCallback<number> } callback - the callback of revokeUriPermission.
216   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
217   * @throws { BusinessError } 401 - Parameter error. Possible causes:
218   *                                 1. Mandatory parameters are left unspecified;
219   *                                 2. Incorrect parameter types.
220   * @throws { BusinessError } 16000050 - Internal error.
221   * @throws { BusinessError } 16000059 - Invalid URI type.
222   * @syscap SystemCapability.Ability.AbilityRuntime.Core
223   * @systemapi hide this for inner system use
224   * @since 12
225   */
226  /**
227   * Revoke URI from one application
228   *
229   * @param { string } uri - File URI.
230   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
231   * @param { AsyncCallback<number> } callback - the callback of revokeUriPermission.
232   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
233   * @throws { BusinessError } 401 - Parameter error. Possible causes:
234   *                                 1. Mandatory parameters are left unspecified;
235   *                                 2. Incorrect parameter types.
236   * @throws { BusinessError } 801 - Capability not supported.
237   * @throws { BusinessError } 16000050 - Internal error.
238   * @throws { BusinessError } 16000059 - Invalid URI type.
239   * @syscap SystemCapability.Ability.AbilityRuntime.Core
240   * @systemapi hide this for inner system use
241   * @since arkts {'1.1':'19', '1.2':'20'}
242   * @arkts 1.1&1.2
243   */
244  function revokeUriPermission(uri: string, targetBundleName: string, callback: AsyncCallback<number>): void;
245
246  /**
247   * Revoke URI from one application
248   *
249   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
250   * @param { string } uri - File URI.
251   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
252   * @returns { Promise<number> } - the promise returned by the function.
253   * @throws { BusinessError } 201 - Permission denied.
254   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
255   * @throws { BusinessError } 401 - Parameter error. Possible causes:
256   *                                 1. Mandatory parameters are left unspecified;
257   *                                 2. Incorrect parameter types.
258   * @throws { BusinessError } 16000050 - Internal error.
259   * @throws { BusinessError } 16000059 - Invalid URI type.
260   * @syscap SystemCapability.Ability.AbilityRuntime.Core
261   * @systemapi hide this for inner system use
262   * @since 10
263   */
264    /**
265   * Revoke URI from one application
266   *
267   * @param { string } uri - File URI.
268   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
269   * @returns { Promise<number> } - the promise returned by the function.
270   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
271   * @throws { BusinessError } 401 - Parameter error. Possible causes:
272   *                                 1. Mandatory parameters are left unspecified;
273   *                                 2. Incorrect parameter types.
274   * @throws { BusinessError } 16000050 - Internal error.
275   * @throws { BusinessError } 16000059 - Invalid URI type.
276   * @syscap SystemCapability.Ability.AbilityRuntime.Core
277   * @systemapi hide this for inner system use
278   * @since 12
279   */
280  /**
281   * Revoke URI from one application
282   *
283   * @param { string } uri - File URI.
284   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
285   * @returns { Promise<number> } - the promise returned by the function.
286   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
287   * @throws { BusinessError } 401 - Parameter error. Possible causes:
288   *                                 1. Mandatory parameters are left unspecified;
289   *                                 2. Incorrect parameter types.
290   * @throws { BusinessError } 801 - Capability not supported.
291   * @throws { BusinessError } 16000050 - Internal error.
292   * @throws { BusinessError } 16000059 - Invalid URI type.
293   * @syscap SystemCapability.Ability.AbilityRuntime.Core
294   * @systemapi hide this for inner system use
295   * @since arkts {'1.1':'19', '1.2':'20'}
296   * @arkts 1.1&1.2
297   */
298  function revokeUriPermission(uri: string, targetBundleName: string): Promise<number>;
299
300  /**
301   * Revoke URI from one application
302   *
303   * @param { string } uri - File URI.
304   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
305   * @param { number } appCloneIndex - Indicates the clone index of target application.
306   * @returns { Promise<void> } - the promise returned by the function.
307   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
308   * @throws { BusinessError } 401 - Parameter error. Possible causes:
309   *                                 1. Mandatory parameters are left unspecified;
310   *                                 2. Incorrect parameter types.
311   * @throws { BusinessError } 16000050 - Internal error.
312   * @throws { BusinessError } 16000059 - Invalid URI type.
313   * @throws { BusinessError } 16000081 - Failed to obtain the target application information.
314   * @syscap SystemCapability.Ability.AbilityRuntime.Core
315   * @systemapi hide this for inner system use
316   * @since 14
317   */
318  /**
319   * Revoke URI from one application
320   *
321   * @param { string } uri - File URI.
322   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
323   * @param { number } appCloneIndex - Indicates the clone index of target application.
324   * @returns { Promise<void> } - the promise returned by the function.
325   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
326   * @throws { BusinessError } 401 - Parameter error. Possible causes:
327   *                                 1. Mandatory parameters are left unspecified;
328   *                                 2. Incorrect parameter types.
329   * @throws { BusinessError } 801 - Capability not supported.
330   * @throws { BusinessError } 16000050 - Internal error.
331   * @throws { BusinessError } 16000059 - Invalid URI type.
332   * @throws { BusinessError } 16000081 - Failed to obtain the target application information.
333   * @syscap SystemCapability.Ability.AbilityRuntime.Core
334   * @systemapi hide this for inner system use
335   * @since arkts {'1.1':'19', '1.2':'20'}
336   * @arkts 1.1&1.2
337   */
338    function revokeUriPermission(uri: string, targetBundleName: string, appCloneIndex: number): Promise<void>;
339
340  /**
341   * Grant URIs in UDkey to another application
342   * @param { string } key - Indicates the unique identifier of target UnifiedData.
343   * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
344   *                                      wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or
345   *                                      wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION.
346   * @param { number } targetTokenId - Indicates the token id of target application.
347   * @returns { Promise<void> } - The promise returned by the function.
348   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
349   * @throws { BusinessError } 801 - Capability not supported.
350   * @throws { BusinessError } 16000050 - Internal error.
351   * @throws { BusinessError } 16000058 - Invalid URI flag.
352   * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission.
353   * @throws { BusinessError } 16000091 - Failed to get the file URI from the key.
354   * @throws { BusinessError } 16000092 - No permission to authorize the URI.
355   * @throws { BusinessError } 16000094 - The target token ID is invalid.
356   * @syscap SystemCapability.Ability.AbilityRuntime.Core
357   * @systemapi Hide this for inner system use.
358   * @since 20
359   */
360  function grantUriPermissionByKey(key: string, flag: wantConstant.Flags, targetTokenId: number): Promise<void>;
361
362  /**
363   * Grant URIs in UDkey to another application
364   * @permission ohos.permission.GRANT_URI_PERMISSION_AS_CALLER
365   * @param { string } key - Indicates the unique identifier of target UnifiedData.
366   * @param { wantConstant.Flags } flag - wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION,
367   *                                      wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION or
368   *                                      wantConstant.Flags.FLAG_AUTH_PERSISTABLE_URI_PERMISSION.
369   * @param { number } callerTokenId - Indicates the token id of caller application.
370   * @param { number } targetTokenId - Indicates the token id of target application.
371   * @returns { Promise<void> } - The promise returned by the function.
372   * @throws { BusinessError } 201 - Permission denied.
373   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
374   * @throws { BusinessError } 801 - Capability not supported.
375   * @throws { BusinessError } 16000050 - Internal error.
376   * @throws { BusinessError } 16000058 - Invalid URI flag.
377   * @throws { BusinessError } 16000060 - A sandbox application cannot grant URI permission.
378   * @throws { BusinessError } 16000091 - Failed to get the file URI from the key.
379   * @throws { BusinessError } 16000092 - No permission to authorize the URI.
380   * @throws { BusinessError } 16000093 - The caller token ID is invalid.
381   * @throws { BusinessError } 16000094 - The target token ID is invalid.
382   * @syscap SystemCapability.Ability.AbilityRuntime.Core
383   * @systemapi Hide this for inner system use.
384   * @since 20
385   */
386  function grantUriPermissionByKeyAsCaller(key: string, flag: wantConstant.Flags, callerTokenId: number, targetTokenId: number): Promise<void>;
387}
388
389export default uriPermissionManager;