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 { AsyncCallback, Callback } from './@ohos.base';
22
23/**
24 * Provides filesystem statistics APIs.
25 *
26 * @namespace storageStatistics
27 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
28 * @since 8
29 */
30declare namespace storageStatistics {
31  /**
32   * Get the total size of volume.
33   *
34   * @permission ohos.permission.STORAGE_MANAGER
35   * @param { string } volumeUuid - The uuid of the volume
36   * @param { AsyncCallback<number> } callback - callback
37   * @throws { BusinessError } 201 - Permission verification failed.
38   * @throws { BusinessError } 202 - The caller is not a system application.
39   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
40parameters are left unspecified;
41   * <br>2.Incorrect parameter types.
42   * @throws { BusinessError } 13600001 - IPC error.
43   * @throws { BusinessError } 13600008 - No such object.
44   * @throws { BusinessError } 13900042 - Unknown error.
45   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
46   * @systemapi
47   * @since 8
48   */
49  function getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void;
50
51  /**
52   * Get the total size of volume.
53   *
54   * @permission ohos.permission.STORAGE_MANAGER
55   * @param { string } volumeUuid - The uuid of the volume
56   * @returns { Promise<number> } return Promise
57   * @throws { BusinessError } 201 - Permission verification failed.
58   * @throws { BusinessError } 202 - The caller is not a system application.
59   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
60parameters are left unspecified;
61   * <br>2.Incorrect parameter types.
62   * @throws { BusinessError } 13600001 - IPC error.
63   * @throws { BusinessError } 13600008 - No such object.
64   * @throws { BusinessError } 13900042 - Unknown error.
65   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
66   * @systemapi
67   * @since 8
68   */
69  function getTotalSizeOfVolume(volumeUuid: string): Promise<number>;
70  /**
71   * Get the free size of volume.
72   *
73   * @permission ohos.permission.STORAGE_MANAGER
74   * @param { string } volumeUuid - The uuid of the volume
75   * @param { AsyncCallback<number> } callback - callback
76   * @throws { BusinessError } 201 - Permission verification failed.
77   * @throws { BusinessError } 202 - The caller is not a system application.
78   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
79parameters are left unspecified;
80   * <br>2.Incorrect parameter types.
81   * @throws { BusinessError } 13600001 - IPC error.
82   * @throws { BusinessError } 13600008 - No such object.
83   * @throws { BusinessError } 13900042 - Unknown error.
84   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
85   * @systemapi
86   * @since 8
87   */
88  function getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void;
89
90  /**
91   * Get the free size of volume.
92   *
93   * @permission ohos.permission.STORAGE_MANAGER
94   * @param { string } volumeUuid - The uuid of the volume
95   * @returns { Promise<number> } return Promise
96   * @throws { BusinessError } 201 - Permission verification failed.
97   * @throws { BusinessError } 202 - The caller is not a system application.
98   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
99parameters are left unspecified;
100   * <br>2.Incorrect parameter types.
101   * @throws { BusinessError } 13600001 - IPC error.
102   * @throws { BusinessError } 13600008 - No such object.
103   * @throws { BusinessError } 13900042 - Unknown error.
104   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
105   * @systemapi
106   * @since 8
107   */
108  function getFreeSizeOfVolume(volumeUuid: string): Promise<number>;
109
110  /**
111   * Get the bundle statistics.
112   *
113   * @interface BundleStats
114   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
115   * @since 9
116   */
117  export interface BundleStats {
118    /**
119     * The size of application installation data.
120     *
121     * @type { number }
122     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
123     * @since 9
124     */
125    appSize: number;
126
127    /**
128     * The size of application cache data.
129     *
130     * @type { number }
131     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
132     * @since 9
133     */
134    cacheSize: number;
135
136    /**
137     * The size of application local data, distributed data and database data.
138     *
139     * @type { number }
140     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
141     * @since 9
142     */
143    dataSize: number;
144  }
145  /**
146   * Get the bundle statistics.
147   *
148   * @permission ohos.permission.STORAGE_MANAGER
149   * @param { string } packageName - The name of the application
150   * @param { AsyncCallback<BundleStats> } callback - callback
151   * @throws { BusinessError } 201 - Permission verification failed.
152   * @throws { BusinessError } 202 - The caller is not a system application.
153   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
154parameters are left unspecified;
155   * <br>2.Incorrect parameter types.
156   * @throws { BusinessError } 13600001 - IPC error.
157   * @throws { BusinessError } 13600008 - No such object.
158   * @throws { BusinessError } 13900042 - Unknown error.
159   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
160   * @systemapi
161   * @since 9
162   */ 
163  /**
164   * Get the bundle statistics.
165   *
166   * @permission ohos.permission.STORAGE_MANAGER
167   * @param { string } packageName - The name of the application
168   * @param { AsyncCallback<BundleStats> } callback - callback
169   * @param { number } index - The index number of the clone application, the default value is 0.
170   * @throws { BusinessError } 201 - Permission verification failed.
171   * @throws { BusinessError } 202 - The caller is not a system application.
172   * @throws { BusinessError } 401 - The input parameter is invalid.
173   * @throws { BusinessError } 13600001 - IPC error.
174   * @throws { BusinessError } 13600008 - No such object.
175   * @throws { BusinessError } 13900042 - Unknown error.
176   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
177   * @systemapi
178   * @since 12
179   */
180  function getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>, index?: number): void;
181
182  /**
183   * Get the bundle statistics.
184   *
185   * @permission ohos.permission.STORAGE_MANAGER
186   * @param { string } packageName - The name of the application
187   * @returns { Promise<BundleStats> } return Promise
188   * @throws { BusinessError } 201 - Permission verification failed.
189   * @throws { BusinessError } 202 - The caller is not a system application.
190   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
191parameters are left unspecified;
192   * <br>2.Incorrect parameter types.
193   * @throws { BusinessError } 13600001 - IPC error.
194   * @throws { BusinessError } 13600008 - No such object.
195   * @throws { BusinessError } 13900042 - Unknown error.
196   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
197   * @systemapi
198   * @since 9
199   */
200  /**
201   * Get the bundle statistics.
202   *
203   * @permission ohos.permission.STORAGE_MANAGER
204   * @param { string } packageName - The name of the application
205   * @param { number } index - The index number of the clone application, the default value is 0.
206   * @returns { Promise<BundleStats> } return Promise
207   * @throws { BusinessError } 201 - Permission verification failed.
208   * @throws { BusinessError } 202 - The caller is not a system application.
209   * @throws { BusinessError } 401 - The input parameter is invalid.
210   * @throws { BusinessError } 13600001 - IPC error.
211   * @throws { BusinessError } 13600008 - No such object.
212   * @throws { BusinessError } 13900042 - Unknown error.
213   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
214   * @systemapi
215   * @since 12
216   */
217  function getBundleStats(packageName: string, index?: number): Promise<BundleStats>;
218
219  /**
220   * Get the current bundle statistics.
221   *
222   * @param { AsyncCallback<BundleStats> } callback - callback
223   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
224parameters are left unspecified;
225   * @throws { BusinessError } 13600001 - IPC error.
226   * @throws { BusinessError } 13900042 - Unknown error.
227   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
228   * @since 9
229   */
230  function getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void;
231
232  /**
233   * Get the current bundle statistics.
234   *
235   * @returns { Promise<BundleStats> } return Promise
236   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
237parameters are left unspecified;
238   * @throws { BusinessError } 13600001 - IPC error.
239   * @throws { BusinessError } 13900042 - Unknown error.
240   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
241   * @since 9
242   */
243  function getCurrentBundleStats(): Promise<BundleStats>;
244
245  /**
246   * Get the system size.
247   *
248   * @permission ohos.permission.STORAGE_MANAGER
249   * @param { AsyncCallback<number> } callback - callback
250   * @throws { BusinessError } 201 - Permission verification failed.
251   * @throws { BusinessError } 202 - The caller is not a system application.
252   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
253parameters are left unspecified;
254   * @throws { BusinessError } 13600001 - IPC error.
255   * @throws { BusinessError } 13900042 - Unknown error.
256   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
257   * @systemapi
258   * @since 9
259   */
260  function getSystemSize(callback: AsyncCallback<number>): void;
261
262  /**
263   * Get the system size.
264   *
265   * @permission ohos.permission.STORAGE_MANAGER
266   * @returns { Promise<number> } return Promise
267   * @throws { BusinessError } 201 - Permission verification failed.
268   * @throws { BusinessError } 202 - The caller is not a system application.
269   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
270parameters are left unspecified;
271   * @throws { BusinessError } 13600001 - IPC error.
272   * @throws { BusinessError } 13900042 - Unknown error.
273   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
274   * @systemapi
275   * @since 9
276   */
277  function getSystemSize(): Promise<number>;
278
279  /**
280   * Get the user storage statistics.
281   *
282   * @interface StorageStats
283   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
284   * @systemapi
285   * @since 9
286   */
287  export interface StorageStats {
288    /**
289     * The total size of device.
290     *
291     * @type { number }
292     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
293     * @systemapi
294     * @since 9
295     */
296    total: number;
297
298    /**
299     * The size of audio file.
300     *
301     * @type { number }
302     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
303     * @systemapi
304     * @since 9
305     */
306    audio: number;
307
308    /**
309     * The size of video file.
310     *
311     * @type { number }
312     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
313     * @systemapi
314     * @since 9
315     */
316    video: number;
317
318    /**
319     * The size of image file.
320     *
321     * @type { number }
322     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
323     * @systemapi
324     * @since 9
325     */
326    image: number;
327
328    /**
329     * The size of other file.
330     *
331     * @type { number }
332     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
333     * @systemapi
334     * @since 9
335     */
336    file: number;
337
338    /**
339     * The size of application.
340     *
341     * @type { number }
342     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
343     * @systemapi
344     * @since 9
345     */
346    app: number;
347  }
348
349  /**
350   * Get the user storage statistics.
351   *
352   * @permission ohos.permission.STORAGE_MANAGER
353   * @returns { Promise<StorageStats> } return Promise
354   * @throws { BusinessError } 201 - Permission verification failed.
355   * @throws { BusinessError } 202 - The caller is not a system application.
356   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
357parameters are left unspecified;
358   * <br>2.Incorrect parameter types.
359   * @throws { BusinessError } 13600001 - IPC error.
360   * @throws { BusinessError } 13900042 - Unknown error.
361   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
362   * @systemapi
363   * @since 9
364   */
365  function getUserStorageStats(): Promise<StorageStats>;
366
367  /**
368   * Get the user storage statistics.
369   *
370   * @permission ohos.permission.STORAGE_MANAGER
371   * @param { AsyncCallback<StorageStats> } callback - callback
372   * @throws { BusinessError } 201 - Permission verification failed.
373   * @throws { BusinessError } 202 - The caller is not a system application.
374   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
375parameters are left unspecified;
376   * <br>2.Incorrect parameter types.
377   * @throws { BusinessError } 13600001 - IPC error.
378   * @throws { BusinessError } 13900042 - Unknown error.
379   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
380   * @systemapi
381   * @since 9
382   */
383  function getUserStorageStats(callback: AsyncCallback<StorageStats>): void;
384
385  /**
386   * Get the user storage statistics.
387   *
388   * @permission ohos.permission.STORAGE_MANAGER
389   * @param { number } userId - The id of the user
390   * @returns { Promise<StorageStats> } return Promise
391   * @throws { BusinessError } 201 - Permission verification failed.
392   * @throws { BusinessError } 202 - The caller is not a system application.
393   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
394parameters are left unspecified;
395   * <br>2.Incorrect parameter types.
396   * @throws { BusinessError } 13600001 - IPC error.
397   * @throws { BusinessError } 13600009 - User if out of range.
398   * @throws { BusinessError } 13900042 - Unknown error.
399   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
400   * @systemapi
401   * @since 9
402   */
403  function getUserStorageStats(userId: number): Promise<StorageStats>;
404
405  /**
406   * Get the user storage statistics.
407   *
408   * @permission ohos.permission.STORAGE_MANAGER
409   * @param { number } userId - The id of the user
410   * @param { AsyncCallback<StorageStats> } callback - callback
411   * @throws { BusinessError } 201 - Permission verification failed.
412   * @throws { BusinessError } 202 - The caller is not a system application.
413   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
414parameters are left unspecified;
415   * <br>2.Incorrect parameter types.
416   * @throws { BusinessError } 13600001 - IPC error.
417   * @throws { BusinessError } 13600009 - User if out of range.
418   * @throws { BusinessError } 13900042 - Unknown error.
419   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
420   * @systemapi
421   * @since 9
422   */
423  function getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>): void;
424
425  /**
426   * Get the total size.
427   *
428   * @permission ohos.permission.STORAGE_MANAGER
429   * @param { AsyncCallback<number> } callback - callback
430   * @throws { BusinessError } 201 - Permission verification failed.
431   * @throws { BusinessError } 202 - The caller is not a system application.
432   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
433parameters are left unspecified;
434   * @throws { BusinessError } 13600001 - IPC error.
435   * @throws { BusinessError } 13900042 - Unknown error.
436   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
437   * @systemapi
438   * @since 9
439   */
440  function getTotalSize(callback: AsyncCallback<number>): void;
441
442  /**
443   * Get the total size.
444   *
445   * @permission ohos.permission.STORAGE_MANAGER
446   * @returns { Promise<number> } return Promise
447   * @throws { BusinessError } 201 - Permission verification failed.
448   * @throws { BusinessError } 202 - The caller is not a system application.
449   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
450parameters are left unspecified;
451   * @throws { BusinessError } 13600001 - IPC error.
452   * @throws { BusinessError } 13900042 - Unknown error.
453   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
454   * @systemapi
455   * @since 9
456   */
457  function getTotalSize(): Promise<number>;
458
459  /**
460   * Get the total size with sync interface
461   *
462   * @permission ohos.permission.STORAGE_MANAGER
463   * @returns { number } return the total size
464   * @throws { BusinessError } 201 - Permission verification failed.
465   * @throws { BusinessError } 202 - The caller is not a system application.
466   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
467parameters are left unspecified;
468   * @throws { BusinessError } 13600001 - IPC error.
469   * @throws { BusinessError } 13900042 - Unknown error.
470   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
471   * @systemapi
472   * @since 10
473   */
474  function getTotalSizeSync(): number;
475
476  /**
477   * Get the free size.
478   *
479   * @permission ohos.permission.STORAGE_MANAGER
480   * @param { AsyncCallback<number> } callback - callback
481   * @throws { BusinessError } 201 - Permission verification failed.
482   * @throws { BusinessError } 202 - The caller is not a system application.
483   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
484parameters are left unspecified;
485   * @throws { BusinessError } 13600001 - IPC error.
486   * @throws { BusinessError } 13900042 - Unknown error.
487   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
488   * @systemapi
489   * @since 9
490   */
491  function getFreeSize(callback: AsyncCallback<number>): void;
492
493  /**
494   * Get the free size.
495   *
496   * @permission ohos.permission.STORAGE_MANAGER
497   * @returns { Promise<number> } return Promise
498   * @throws { BusinessError } 201 - Permission verification failed.
499   * @throws { BusinessError } 202 - The caller is not a system application.
500   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
501parameters are left unspecified;
502   * @throws { BusinessError } 13600001 - IPC error.
503   * @throws { BusinessError } 13900042 - Unknown error.
504   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
505   * @systemapi
506   * @since 9
507   */
508  function getFreeSize(): Promise<number>;
509
510  /**
511   * Get the free size with sync interface.
512   *
513   * @permission ohos.permission.STORAGE_MANAGER
514   * @returns { number } return the free size
515   * @throws { BusinessError } 201 - Permission verification failed.
516   * @throws { BusinessError } 202 - The caller is not a system application.
517   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
518parameters are left unspecified;
519   * @throws { BusinessError } 13600001 - IPC error.
520   * @throws { BusinessError } 13900042 - Unknown error.
521   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
522   * @systemapi
523   * @since 10
524   */
525  function getFreeSizeSync(): number;
526}
527
528export default storageStatistics;
529