• 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 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 - Sandbox application can not 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 - Sandbox application can not 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   * Revoke URI from one application
89   *
90   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
91   * @param { string } uri - File URI.
92   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
93   * @param { AsyncCallback<number> } callback - the callback of revokeUriPermission.
94   * @throws { BusinessError } 201 - Permission denied.
95   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
96   * @throws { BusinessError } 401 - Parameter error. Possible causes:
97   *                                 1. Mandatory parameters are left unspecified;
98   *                                 2. Incorrect parameter types.
99   * @throws { BusinessError } 16000050 - Internal error.
100   * @throws { BusinessError } 16000059 - Invalid URI type.
101   * @syscap SystemCapability.Ability.AbilityRuntime.Core
102   * @systemapi hide this for inner system use
103   * @since 10
104   */
105  /**
106   * Revoke URI from one application
107   *
108   * @param { string } uri - File URI.
109   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
110   * @param { AsyncCallback<number> } callback - the callback of revokeUriPermission.
111   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
112   * @throws { BusinessError } 401 - Parameter error. Possible causes:
113   *                                 1. Mandatory parameters are left unspecified;
114   *                                 2. Incorrect parameter types.
115   * @throws { BusinessError } 16000050 - Internal error.
116   * @throws { BusinessError } 16000059 - Invalid URI type.
117   * @syscap SystemCapability.Ability.AbilityRuntime.Core
118   * @systemapi hide this for inner system use
119   * @since 12
120   */
121  function revokeUriPermission(uri: string, targetBundleName: string, callback: AsyncCallback<number>): void;
122
123  /**
124   * Revoke URI from one application
125   *
126   * @permission ohos.permission.PROXY_AUTHORIZATION_URI
127   * @param { string } uri - File URI.
128   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
129   * @returns { Promise<number> } - the promise returned by the function.
130   * @throws { BusinessError } 201 - Permission denied.
131   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
132   * @throws { BusinessError } 401 - Parameter error. Possible causes:
133   *                                 1. Mandatory parameters are left unspecified;
134   *                                 2. Incorrect parameter types.
135   * @throws { BusinessError } 16000050 - Internal error.
136   * @throws { BusinessError } 16000059 - Invalid URI type.
137   * @syscap SystemCapability.Ability.AbilityRuntime.Core
138   * @systemapi hide this for inner system use
139   * @since 10
140   */
141    /**
142   * Revoke URI from one application
143   *
144   * @param { string } uri - File URI.
145   * @param { string } targetBundleName - Indicates the bundle name of authorization target.
146   * @returns { Promise<number> } - the promise returned by the function.
147   * @throws { BusinessError } 202 - Not System App. Interface caller is not a system app.
148   * @throws { BusinessError } 401 - Parameter error. Possible causes:
149   *                                 1. Mandatory parameters are left unspecified;
150   *                                 2. Incorrect parameter types.
151   * @throws { BusinessError } 16000050 - Internal error.
152   * @throws { BusinessError } 16000059 - Invalid URI type.
153   * @syscap SystemCapability.Ability.AbilityRuntime.Core
154   * @systemapi hide this for inner system use
155   * @since 12
156   */
157  function revokeUriPermission(uri: string, targetBundleName: string): Promise<number>;
158}
159
160export default uriPermissionManager;