• 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 { 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 - Permission Denied. Possible causes:
226May need permission ohos.permission.STORAGE_MANAGER.
227   * @throws { BusinessError } 13900042 - Unknown error.
228   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
229   * @since 9
230   */
231  function getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void;
232
233  /**
234   * Get the current bundle statistics.
235   *
236   * @returns { Promise<BundleStats> } return Promise
237   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
238parameters are left unspecified;
239   * @throws { BusinessError } 13600001 - Permission Denied. Possible causes:
240May need permission ohos.permission.STORAGE_MANAGER.
241   * @throws { BusinessError } 13900042 - Unknown error.
242   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
243   * @since 9
244   */
245  function getCurrentBundleStats(): Promise<BundleStats>;
246
247  /**
248   * Get the system size.
249   *
250   * @permission ohos.permission.STORAGE_MANAGER
251   * @param { AsyncCallback<number> } callback - callback
252   * @throws { BusinessError } 201 - Permission verification failed.
253   * @throws { BusinessError } 202 - The caller is not a system application.
254   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
255parameters are left unspecified;
256   * @throws { BusinessError } 13600001 - IPC error.
257   * @throws { BusinessError } 13900042 - Unknown error.
258   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
259   * @systemapi
260   * @since 9
261   */
262  function getSystemSize(callback: AsyncCallback<number>): void;
263
264  /**
265   * Get the system size.
266   *
267   * @permission ohos.permission.STORAGE_MANAGER
268   * @returns { Promise<number> } return Promise
269   * @throws { BusinessError } 201 - Permission verification failed.
270   * @throws { BusinessError } 202 - The caller is not a system application.
271   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
272parameters are left unspecified;
273   * @throws { BusinessError } 13600001 - IPC error.
274   * @throws { BusinessError } 13900042 - Unknown error.
275   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
276   * @systemapi
277   * @since 9
278   */
279  function getSystemSize(): Promise<number>;
280
281  /**
282   * Get the user storage statistics.
283   *
284   * @interface StorageStats
285   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
286   * @systemapi
287   * @since 9
288   */
289  export interface StorageStats {
290    /**
291     * The total size of device.
292     *
293     * @type { number }
294     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
295     * @systemapi
296     * @since 9
297     */
298    total: number;
299
300    /**
301     * The size of audio file.
302     *
303     * @type { number }
304     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
305     * @systemapi
306     * @since 9
307     */
308    audio: number;
309
310    /**
311     * The size of video file.
312     *
313     * @type { number }
314     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
315     * @systemapi
316     * @since 9
317     */
318    video: number;
319
320    /**
321     * The size of image file.
322     *
323     * @type { number }
324     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
325     * @systemapi
326     * @since 9
327     */
328    image: number;
329
330    /**
331     * The size of other file.
332     *
333     * @type { number }
334     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
335     * @systemapi
336     * @since 9
337     */
338    file: number;
339
340    /**
341     * The size of application.
342     *
343     * @type { number }
344     * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
345     * @systemapi
346     * @since 9
347     */
348    app: number;
349  }
350
351  /**
352   * Get the user storage statistics.
353   *
354   * @permission ohos.permission.STORAGE_MANAGER
355   * @returns { Promise<StorageStats> } return Promise
356   * @throws { BusinessError } 201 - Permission verification failed.
357   * @throws { BusinessError } 202 - The caller is not a system application.
358   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
359parameters are left unspecified;
360   * <br>2.Incorrect parameter types.
361   * @throws { BusinessError } 13600001 - IPC error.
362   * @throws { BusinessError } 13900042 - Unknown error.
363   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
364   * @systemapi
365   * @since 9
366   */
367  function getUserStorageStats(): Promise<StorageStats>;
368
369  /**
370   * Get the user storage statistics.
371   *
372   * @permission ohos.permission.STORAGE_MANAGER
373   * @param { AsyncCallback<StorageStats> } callback - callback
374   * @throws { BusinessError } 201 - Permission verification failed.
375   * @throws { BusinessError } 202 - The caller is not a system application.
376   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
377parameters are left unspecified;
378   * <br>2.Incorrect parameter types.
379   * @throws { BusinessError } 13600001 - IPC error.
380   * @throws { BusinessError } 13900042 - Unknown error.
381   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
382   * @systemapi
383   * @since 9
384   */
385  function getUserStorageStats(callback: AsyncCallback<StorageStats>): void;
386
387  /**
388   * Get the user storage statistics.
389   *
390   * @permission ohos.permission.STORAGE_MANAGER
391   * @param { number } userId - The id of the user
392   * @returns { Promise<StorageStats> } return Promise
393   * @throws { BusinessError } 201 - Permission verification failed.
394   * @throws { BusinessError } 202 - The caller is not a system application.
395   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
396parameters are left unspecified;
397   * <br>2.Incorrect parameter types.
398   * @throws { BusinessError } 13600001 - IPC error.
399   * @throws { BusinessError } 13600009 - User if out of range.
400   * @throws { BusinessError } 13900042 - Unknown error.
401   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
402   * @systemapi
403   * @since 9
404   */
405  function getUserStorageStats(userId: number): Promise<StorageStats>;
406
407  /**
408   * Get the user storage statistics.
409   *
410   * @permission ohos.permission.STORAGE_MANAGER
411   * @param { number } userId - The id of the user
412   * @param { AsyncCallback<StorageStats> } callback - callback
413   * @throws { BusinessError } 201 - Permission verification failed.
414   * @throws { BusinessError } 202 - The caller is not a system application.
415   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory
416parameters are left unspecified;
417   * <br>2.Incorrect parameter types.
418   * @throws { BusinessError } 13600001 - IPC error.
419   * @throws { BusinessError } 13600009 - User if out of range.
420   * @throws { BusinessError } 13900042 - Unknown error.
421   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
422   * @systemapi
423   * @since 9
424   */
425  function getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>): void;
426
427  /**
428   * Get the total size.
429   *
430   * @permission ohos.permission.STORAGE_MANAGER
431   * @param { AsyncCallback<number> } callback - callback
432   * @throws { BusinessError } 201 - Permission verification failed.
433   * @throws { BusinessError } 202 - The caller is not a system application.
434   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
435parameters are left unspecified;
436   * @throws { BusinessError } 13600001 - IPC error.
437   * @throws { BusinessError } 13900042 - Unknown error.
438   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
439   * @systemapi
440   * @since 9
441   */
442  /**
443   * Get the total size.
444   *
445   * @param { AsyncCallback<number> } callback - callback
446   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
447parameters are left unspecified;
448   * @throws { BusinessError } 13600001 - Permission Denied. Possible causes:
449May need permission ohos.permission.STORAGE_MANAGER.
450   * @throws { BusinessError } 13900042 - Unknown error.
451   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
452   * @since 15
453   */
454  function getTotalSize(callback: AsyncCallback<number>): void;
455
456  /**
457   * Get the total size.
458   *
459   * @permission ohos.permission.STORAGE_MANAGER
460   * @returns { Promise<number> } return Promise
461   * @throws { BusinessError } 201 - Permission verification failed.
462   * @throws { BusinessError } 202 - The caller is not a system application.
463   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
464parameters are left unspecified;
465   * @throws { BusinessError } 13600001 - IPC error.
466   * @throws { BusinessError } 13900042 - Unknown error.
467   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
468   * @systemapi
469   * @since 9
470   */
471  /**
472   * Get the total size.
473   *
474   * @returns { Promise<number> } return Promise
475   * @throws { BusinessError } 13600001 - Permission Denied. Possible causes:
476May need permission ohos.permission.STORAGE_MANAGER.
477   * @throws { BusinessError } 13900042 - Unknown error.
478   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
479   * @since 15
480   */
481  function getTotalSize(): Promise<number>;
482
483  /**
484   * Get the total size with sync interface
485   *
486   * @permission ohos.permission.STORAGE_MANAGER
487   * @returns { number } return the total size
488   * @throws { BusinessError } 201 - Permission verification failed.
489   * @throws { BusinessError } 202 - The caller is not a system application.
490   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
491parameters are left unspecified;
492   * @throws { BusinessError } 13600001 - IPC error.
493   * @throws { BusinessError } 13900042 - Unknown error.
494   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
495   * @systemapi
496   * @since 10
497   */
498  /**
499   * Get the total size with sync interface
500   *
501   * @returns { number } return the total size
502   * @throws { BusinessError } 13600001 - Permission Denied. Possible causes:
503May need permission ohos.permission.STORAGE_MANAGER.
504   * @throws { BusinessError } 13900042 - Unknown error.
505   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
506   * @since 15
507   */
508  function getTotalSizeSync(): number;
509
510  /**
511   * Get the free size.
512   *
513   * @permission ohos.permission.STORAGE_MANAGER
514   * @param { AsyncCallback<number> } callback - callback
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 9
524   */
525  /**
526   * Get the free size.
527   *
528   * @param { AsyncCallback<number> } callback - callback
529   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
530parameters are left unspecified;
531   * @throws { BusinessError } 13600001 - Permission Denied. Possible causes:
532May need permission ohos.permission.STORAGE_MANAGER.
533   * @throws { BusinessError } 13900042 - Unknown error.
534   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
535   * @since 15
536   */
537  function getFreeSize(callback: AsyncCallback<number>): void;
538
539  /**
540   * Get the free size.
541   *
542   * @permission ohos.permission.STORAGE_MANAGER
543   * @returns { Promise<number> } return Promise
544   * @throws { BusinessError } 201 - Permission verification failed.
545   * @throws { BusinessError } 202 - The caller is not a system application.
546   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
547parameters are left unspecified;
548   * @throws { BusinessError } 13600001 - IPC error.
549   * @throws { BusinessError } 13900042 - Unknown error.
550   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
551   * @systemapi
552   * @since 9
553   */
554  /**
555   * Get the free size.
556   *
557   * @returns { Promise<number> } return Promise
558   * @throws { BusinessError } 13600001 - Permission Denied. Possible causes:
559May need permission ohos.permission.STORAGE_MANAGER.
560   * @throws { BusinessError } 13900042 - Unknown error.
561   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
562   * @since 15
563   */
564  function getFreeSize(): Promise<number>;
565
566  /**
567   * Get the free size with sync interface.
568   *
569   * @permission ohos.permission.STORAGE_MANAGER
570   * @returns { number } return the free size
571   * @throws { BusinessError } 201 - Permission verification failed.
572   * @throws { BusinessError } 202 - The caller is not a system application.
573   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory
574parameters are left unspecified;
575   * @throws { BusinessError } 13600001 - IPC error.
576   * @throws { BusinessError } 13900042 - Unknown error.
577   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
578   * @systemapi
579   * @since 10
580   */
581  /**
582   * Get the free size with sync interface.
583   *
584   * @returns { number } return the free size
585   * @throws { BusinessError } 13600001 - Permission Denied. Possible causes:
586May need permission ohos.permission.STORAGE_MANAGER.
587   * @throws { BusinessError } 13900042 - Unknown error.
588   * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics
589   * @since 15
590   */
591  function getFreeSizeSync(): number;
592}
593
594export default storageStatistics;
595