• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022-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 CoreFileKit
19 */
20
21import type { AsyncCallback, Callback } from './@ohos.base';
22import type wantConstant from './@ohos.ability.wantConstant';
23
24/**
25 * Provides fileshare APIS
26 *
27 * @namespace fileShare
28 * @syscap SystemCapability.FileManagement.AppFileService
29 * @since 9
30 */
31declare namespace fileShare {
32  /**
33   * Enumerates the uri operate mode types.
34   *
35   * @enum { number } OperationMode
36   * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
37   * @since 11
38   */
39  export enum OperationMode {
40    /**
41     * Indicates read permissions.
42     *
43     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
44     * @since 11
45     */
46    READ_MODE = 0b1,
47
48    /**
49     * Indicates write permissions.
50     *
51     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
52     * @since 11
53     */
54    WRITE_MODE = 0b10,
55  }
56
57  /**
58   * Enumerates the error code of the permission policy for the URI operation.
59   *
60   * @enum { number } PolicyErrorCode
61   * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
62   * @since 11
63   */
64  export enum PolicyErrorCode {
65    /**
66     * Indicates that the policy is not allowed to be persisted.
67     *
68     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
69     * @since 11
70     */
71    PERSISTENCE_FORBIDDEN = 1,
72
73    /**
74     * Indicates that the mode of this policy is invalid.
75     *
76     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
77     * @since 11
78     */
79    INVALID_MODE = 2,
80
81    /**
82     * Indicates that the path of this policy is invalid.
83     *
84     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
85     * @since 11
86     */
87    INVALID_PATH = 3,
88  }
89
90  /**
91   * Failed policy result on URI.
92   *
93   * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
94   * @since 11
95   */
96  export type PolicyErrorResult = {
97    /**
98     * Indicates the failed uri of the policy information.
99     *
100     * @type { string }
101     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
102     * @since 11
103     */
104    uri: string;
105
106    /**
107     * Indicates the error code of the failure in the policy information.
108     *
109     * @type { PolicyErrorCode }
110     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
111     * @since 11
112     */
113    code: PolicyErrorCode;
114
115    /**
116     * Indicates the reason of the failure in the policy information.
117     *
118     * @type { string }
119     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
120     * @since 11
121     */
122    message: string;
123  };
124
125  /**
126   * Policy information to manager permissions on a URI.
127   *
128   * @interface PolicyInfo
129   * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
130   * @since 11
131   */
132  export interface PolicyInfo {
133    /**
134     * Indicates the uri of the policy information.
135     *
136     * @type { string }
137     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
138     * @since 11
139     */
140    uri: string;
141
142    /**
143     * Indicates the mode of operation for the URI, example { OperationMode.READ_MODE } or { OperationMode.READ_MODE | OperationMode.WRITE_MODE }
144     *
145     * @type { number }
146     * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
147     * @since 11
148     */
149    operationMode: number;
150  }
151
152  /**
153   * Provides grant uri permission for app
154   *
155   * @permission ohos.permission.WRITE_MEDIA
156   * @param { string } uri uri
157   * @param { string } bundleName bundleName
158   * @param { wantConstant.Flags } flag wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION or wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION
159   * @param { AsyncCallback<void> } callback
160   * @throws { BusinessError } 201 - Permission verification failed
161   * @throws { BusinessError } 202 - The caller is not a system application
162   * @throws { BusinessError } 401 - The input parameter is invalid
163   * @throws { BusinessError } 143000001 - IPC error
164   * @syscap SystemCapability.FileManagement.AppFileService
165   * @systemapi
166   * @since 9
167   */
168  function grantUriPermission(
169    uri: string,
170    bundleName: string,
171    flag: wantConstant.Flags,
172    callback: AsyncCallback<void>
173  ): void;
174
175  /**
176   * Provides grant uri permission for app
177   *
178   * @permission ohos.permission.WRITE_MEDIA
179   * @param { string } uri uri
180   * @param { string } bundleName bundleName
181   * @param { wantConstant.Flags } flag wantConstant.Flags.FLAG_AUTH_READ_URI_PERMISSION or wantConstant.Flags.FLAG_AUTH_WRITE_URI_PERMISSION
182   * @returns { Promise<void> } no callback return Promise otherwise return void
183   * @throws { BusinessError } 201 - Permission verification failed
184   * @throws { BusinessError } 202 - The caller is not a system application
185   * @throws { BusinessError } 401 - The input parameter is invalid
186   * @throws { BusinessError } 143000001 - IPC error
187   * @syscap SystemCapability.FileManagement.AppFileService
188   * @systemapi
189   * @since 9
190   */
191  function grantUriPermission(uri: string, bundleName: string, flag: wantConstant.Flags): Promise<void>;
192
193  /**
194   * Set persistence permissions for the URI
195   *
196   * @permission ohos.permission.FILE_ACCESS_PERSIST
197   * @param { Array<PolicyInfo> } policies - Policy information to grant permission on URIs.
198   * @returns { Promise<void> } the promise returned by the function.
199   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
200   * @throws { BusinessError } 401 - Parameter error.
201   * @throws { BusinessError } 801 - Capability not supported.
202   * @throws { BusinessError } 13900001 - Operation not permitted.
203   * @throws { BusinessError } 13900042 - Unknown error
204   * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
205   * @since 11
206   */
207  function persistPermission(policies: Array<PolicyInfo>): Promise<void>;
208
209  /**
210   * Revoke persistence permissions for the URI
211   *
212   * @permission ohos.permission.FILE_ACCESS_PERSIST
213   * @param { Array<PolicyInfo> } policies - Policy information to grant permission on URIs.
214   * @returns { Promise<void> } the promise returned by the function.
215   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
216   * @throws { BusinessError } 401 - Parameter error.
217   * @throws { BusinessError } 801 - Capability not supported.
218   * @throws { BusinessError } 13900001 - Operation not permitted.
219   * @throws { BusinessError } 13900042 - Unknown error
220   * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
221   * @since 11
222   */
223  function revokePermission(policies: Array<PolicyInfo>): Promise<void>;
224
225  /**
226   * Enable the URI that have been permanently authorized
227   *
228   * @permission ohos.permission.FILE_ACCESS_PERSIST
229   * @param { Array<PolicyInfo> } policies - Policy information to grant permission on URIs.
230   * @returns { Promise<void> } the promise returned by the function.
231   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
232   * @throws { BusinessError } 401 - Parameter error.
233   * @throws { BusinessError } 801 - Capability not supported.
234   * @throws { BusinessError } 13900001 - Operation not permitted.
235   * @throws { BusinessError } 13900042 - Unknown error
236   * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
237   * @since 11
238   */
239  function activatePermission(policies: Array<PolicyInfo>): Promise<void>;
240
241  /**
242   * Stop the authorized URI that has been enabled
243   *
244   * @permission ohos.permission.FILE_ACCESS_PERSIST
245   * @param { Array<PolicyInfo> } policies - Policy information to grant permission on URIs.
246   * @returns { Promise<void> } the promise returned by the function.
247   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
248   * @throws { BusinessError } 401 - Parameter error.
249   * @throws { BusinessError } 801 - Capability not supported.
250   * @throws { BusinessError } 13900001 - Operation not permitted.
251   * @throws { BusinessError } 13900042 - Unknown error
252   * @syscap SystemCapability.FileManagement.AppFileService.FolderAuthorization
253   * @since 11
254   */
255  function deactivatePermission(policies: Array<PolicyInfo>): Promise<void>;
256}
257
258export default fileShare;
259