• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.storageStatistics (Application Storage Statistics) (System API)
2
3The **storageStatistics** module provides APIs for obtaining storage space information, including the space of built-in and plug-in memory cards, space occupied by different types of data, and space of application data.
4
5> **NOTE**
6>
7> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.file.storageStatistics](js-apis-file-storage-statistics-sys.md).
9
10## Modules to Import
11
12```ts
13import storageStatistics from "@ohos.file.storageStatistics";
14```
15
16## storageStatistics.getTotalSizeOfVolume
17
18getTotalSizeOfVolume(volumeUuid: string): Promise<number>
19
20Obtains the total space of a volume in an external storage device, in bytes. This API uses a promise to return the result.
21
22**Required permissions**: ohos.permission.STORAGE_MANAGER
23
24**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
25
26**System API**: This is a system API.
27
28**Parameters**
29
30  | Name    | Type  | Mandatory| Description|
31  | ---------- | ------ | ---- | ---- |
32  | volumeUuid | string | Yes  | UUID of the volume.|
33
34**Return value**
35
36  | Type                 | Description            |
37  | --------------------- | ---------------- |
38  | Promise<number> | Promise used to return the total volume space obtained.|
39
40**Error codes**
41
42For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
43
44| ID| Error Message|
45| -------- | -------- |
46| 201 | Permission verification failed. |
47| 202 | The caller is not a system application. |
48| 401 | The input parameter is invalid. |
49| 13600001 | IPC error. |
50| 13600008 | No such object. |
51| 13900042 | Unknown error. |
52
53**Example**
54
55  ```ts
56  import volumemanager from "@ohos.file.volumeManager";
57  import { BusinessError } from '@ohos.base';
58  volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => {
59    let uuid: string = volumes[0].uuid;
60    storageStatistics.getTotalSizeOfVolume(uuid).then((number: number) => {
61      console.info("getTotalSizeOfVolume successfully:" + number);
62    }).catch((err: BusinessError) => {
63      console.error("getTotalSizeOfVolume failed with error:" + JSON.stringify(err));
64    });
65  }).catch((err: BusinessError) => {
66    console.error("getAllVolumes failed with error:" + JSON.stringify(err));
67  });
68  ```
69
70## storageStatistics.getTotalSizeOfVolume
71
72getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback&lt;number&gt;): void
73
74Obtains the total space of a volume in an external storage device, in bytes. This API uses an asynchronous callback to return the result.
75
76**Required permissions**: ohos.permission.STORAGE_MANAGER
77
78**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
79
80**System API**: This is a system API.
81
82**Parameters**
83
84  | Name    | Type                                | Mandatory| Description                      |
85  | ---------- | ------------------------------------ | ---- | -------------------------- |
86  | volumeUuid | string                               | Yes  | UUID of the volume.                      |
87  | callback   | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the total volume space obtained.|
88
89**Error codes**
90
91For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
92
93| ID| Error Message|
94| -------- | -------- |
95| 201 | Permission verification failed. |
96| 202 | The caller is not a system application. |
97| 401 | The input parameter is invalid. |
98| 13600001 | IPC error. |
99| 13600008 | No such object. |
100| 13900042 | Unknown error. |
101
102**Example**
103
104  ```ts
105  import volumemanager from "@ohos.file.volumeManager";
106  import { BusinessError } from '@ohos.base';
107  volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => {
108    let uuid: string = volumes[0].uuid;
109    storageStatistics.getTotalSizeOfVolume(uuid, (error: BusinessError, number: number) => {
110      if (error) {
111        console.error("getTotalSizeOfVolume failed with error:" + JSON.stringify(error));
112      } else {
113        // Do something.
114        console.info("getTotalSizeOfVolume successfully:" + number);
115      }
116    });
117  }).catch((err: BusinessError) => {
118    console.error("getAllVolumes failed with error:" + JSON.stringify(err));
119  });
120  ```
121
122## storageStatistics.getFreeSizeOfVolume
123
124getFreeSizeOfVolume(volumeUuid: string): Promise&lt;number&gt;
125
126Obtains the available space of a volume in an external storage device, in bytes. This API uses a promise to return the result.
127
128**Required permissions**: ohos.permission.STORAGE_MANAGER
129
130**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
131
132**System API**: This is a system API.
133
134**Parameters**
135
136  | Name    | Type  | Mandatory| Description|
137  | ---------- | ------ | ---- | ---- |
138  | volumeUuid | string | Yes  | UUID of the volume.|
139
140**Return value**
141
142  | Type                 | Description              |
143  | --------------------- | ------------------ |
144  | Promise&lt;number&gt; | Promise used to return the available volume space obtained.|
145
146**Error codes**
147
148For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
149
150| ID| Error Message|
151| -------- | -------- |
152| 201 | Permission verification failed. |
153| 202 | The caller is not a system application. |
154| 401 | The input parameter is invalid. |
155| 13600001 | IPC error. |
156| 13600008 | No such object. |
157| 13900042 | Unknown error. |
158
159**Example**
160
161  ```ts
162  import volumemanager from "@ohos.file.volumeManager";
163  import { BusinessError } from '@ohos.base';
164  volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => {
165    let uuid: string = volumes[0].uuid;
166    storageStatistics.getFreeSizeOfVolume(uuid).then((number: number) => {
167      console.info("getFreeSizeOfVolume successfully:" + number);
168    }).catch((err: BusinessError) => {
169      console.error("getFreeSizeOfVolume failed with error:" + JSON.stringify(err));
170    });
171  }).catch((err: BusinessError) => {
172    console.error("getAllVolumes failed with error:" + JSON.stringify(err));
173  });
174  ```
175
176## storageStatistics.getFreeSizeOfVolume
177
178getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback&lt;number&gt;): void
179
180Obtains the available space of a volume in an external storage device, in bytes. This API uses an asynchronous callback to return the result.
181
182**Required permissions**: ohos.permission.STORAGE_MANAGER
183
184**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
185
186**System API**: This is a system API.
187
188**Parameters**
189
190  | Name    | Type                                | Mandatory| Description                        |
191  | ---------- | ------------------------------------ | ---- | ---------------------------- |
192  | volumeUuid | string                               | Yes  | UUID of the volume.                        |
193  | callback   | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the available volume space obtained.|
194
195**Error codes**
196
197For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
198
199| ID| Error Message|
200| -------- | -------- |
201| 201 | Permission verification failed. |
202| 202 | The caller is not a system application. |
203| 401 | The input parameter is invalid. |
204| 13600001 | IPC error. |
205| 13600008 | No such object. |
206| 13900042 | Unknown error. |
207
208**Example**
209
210  ```ts
211  import volumemanager from "@ohos.file.volumeManager";
212  import { BusinessError } from '@ohos.base';
213  volumemanager.getAllVolumes().then((volumes: Array<volumemanager.Volume>) => {
214    let uuid: string = volumes[0].uuid;
215    storageStatistics.getFreeSizeOfVolume(uuid, (error: BusinessError, number: number) => {
216      if (error) {
217        console.error("getFreeSizeOfVolume failed with error:" + JSON.stringify(error));
218      } else {
219        // Do something.
220        console.info("getFreeSizeOfVolume successfully: " + number);
221      }
222    });
223  }).catch((err: BusinessError) => {
224    console.error("getAllVolumes failed with error:" + JSON.stringify(err));
225  });
226  ```
227
228## storageStatistics.getBundleStats<sup>9+</sup>
229
230getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
231
232Obtains the storage space of an application, in bytes. This API uses a promise to return the result.
233
234**Required permissions**: ohos.permission.STORAGE_MANAGER
235
236**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
237
238**System API**: This is a system API.
239
240**Parameters**
241
242  | Name     | Type  | Mandatory| Description    |
243  | ----------- | ------ | ---- | -------- |
244  | packageName | string | Yes  | Bundle name.|
245
246**Return value**
247
248  | Type                                      | Description                      |
249  | ------------------------------------------ | -------------------------- |
250  | Promise&lt;[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)&gt; | Promise used to return the application storage space obtained.|
251
252**Error codes**
253
254For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
255
256| ID| Error Message|
257| -------- | -------- |
258| 201 | Permission verification failed. |
259| 202 | The caller is not a system application. |
260| 401 | The input parameter is invalid. |
261| 13600001 | IPC error. |
262| 13600008 | No such object. |
263| 13900042 | Unknown error. |
264
265**Example**
266
267  ```ts
268  import { BusinessError } from '@ohos.base';
269  let packageName: string = "";
270  storageStatistics.getBundleStats(packageName).then((BundleStats: storageStatistics.BundleStats) => {
271    console.info("getBundleStats successfully:" + JSON.stringify(BundleStats));
272  }).catch((err: BusinessError) => {
273    console.error("getBundleStats failed with error:" + JSON.stringify(err));
274  });
275  ```
276
277## storageStatistics.getBundleStats<sup>9+</sup>
278
279getBundleStats(packageName: string,  callback: AsyncCallback&lt;BundleStats&gt;): void
280
281Obtains the storage space of an application, in bytes. This API uses an asynchronous callback to return the result.
282
283**Required permissions**: ohos.permission.STORAGE_MANAGER
284
285**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
286
287**System API**: This is a system API.
288
289**Parameters**
290
291  | Name  | Type                                                     | Mandatory| Description                                |
292  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
293  | packageName | string | Yes  | Bundle name.|
294  | callback | AsyncCallback&lt;[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)&gt; | Yes  | Callback invoked to return the application storage space obtained.|
295
296**Error codes**
297
298For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
299
300| ID| Error Message|
301| -------- | -------- |
302| 201 | Permission verification failed. |
303| 202 | The caller is not a system application. |
304| 401 | The input parameter is invalid. |
305| 13600001 | IPC error. |
306| 13600008 | No such object. |
307| 13900042 | Unknown error. |
308
309**Example**
310
311  ```ts
312  import { BusinessError } from '@ohos.base';
313  let packageName: string = "";
314  storageStatistics.getBundleStats(packageName, (error: BusinessError, BundleStats: storageStatistics.BundleStats) => {
315    if (error) {
316      console.error("getBundleStats failed with error:" + JSON.stringify(error));
317    }  else {
318      // Do something.
319      console.info("getBundleStats successfully:" + JSON.stringify(BundleStats));
320    }
321  });
322  ```
323
324## storageStatistics.getTotalSize<sup>9+</sup>
325
326getTotalSize(): Promise&lt;number&gt;
327
328Obtains the total space of the built-in storage, in bytes. This API uses a promise to return the result.
329
330**Required permissions**: ohos.permission.STORAGE_MANAGER
331
332**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
333
334**System API**: This is a system API.
335
336**Return value**
337
338  | Type                  | Description              |
339  | --------------------- | ------------------ |
340  | Promise&lt;number&gt; | Promise used to return the total built-in storage space obtained.  |
341
342**Error codes**
343
344For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
345
346| ID| Error Message|
347| -------- | -------- |
348| 201 | Permission verification failed. |
349| 202 | The caller is not a system application. |
350| 401 | The input parameter is invalid. |
351| 13600001 | IPC error. |
352| 13900042 | Unknown error. |
353
354**Example**
355
356  ```ts
357  import { BusinessError } from '@ohos.base';
358  storageStatistics.getTotalSize().then((number: number) => {
359    console.info("getTotalSize successfully:" + JSON.stringify(number));
360  }).catch((err: BusinessError) => {
361    console.error("getTotalSize failed with error:"+ JSON.stringify(err));
362  });
363  ```
364
365## storageStatistics.getTotalSize<sup>9+</sup>
366
367getTotalSize(callback: AsyncCallback&lt;number&gt;): void
368
369Obtains the total space of the built-in storage, in bytes. This API uses an asynchronous callback to return the result.
370
371**Required permissions**: ohos.permission.STORAGE_MANAGER
372
373**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
374
375**System API**: This is a system API.
376
377**Parameters**
378
379  | Name   | Type                                 | Mandatory | Description                    |
380  | -------- | ------------------------------------ | ---- | ------------------------ |
381  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the built-in storage space obtained.|
382
383**Error codes**
384
385For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
386
387| ID| Error Message|
388| -------- | -------- |
389| 201 | Permission verification failed. |
390| 202 | The caller is not a system application. |
391| 401 | The input parameter is invalid. |
392| 13600001 | IPC error. |
393| 13900042 | Unknown error. |
394
395**Example**
396
397  ```ts
398  import { BusinessError } from '@ohos.base';
399  storageStatistics.getTotalSize((error: BusinessError, number: number) => {
400    if (error) {
401      console.error("getTotalSize failed with error:" + JSON.stringify(error));
402    } else {
403      // Do something.
404      console.info("getTotalSize successfully:" + number);
405    }
406  });
407  ```
408
409## storageStatistics.getTotalSizeSync<sup>10+</sup>
410
411getTotalSizeSync(): number
412
413Obtains the total space of the built-in storage, in bytes. This API returns the result synchronously.
414
415**Required permissions**: ohos.permission.STORAGE_MANAGER
416
417**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
418
419**System API**: This is a system API.
420
421**Return value**
422
423  | Type                  | Description              |
424  | --------------------- | ------------------ |
425  | number | Built-in storage space obtained.  |
426
427**Error codes**
428
429For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
430
431| ID| Error Message|
432| -------- | -------- |
433| 201 | Permission verification failed. |
434| 202 | The caller is not a system application. |
435| 401 | The input parameter is invalid. |
436| 13600001 | IPC error. |
437| 13900042 | Unknown error. |
438
439**Example**
440
441  ```ts
442  import { BusinessError } from '@ohos.base';
443  try {
444    let number = storageStatistics.getTotalSizeSync();
445    console.info("getTotalSizeSync successfully:" + JSON.stringify(number));
446  } catch (err) {
447    let error: BusinessError = err as BusinessError;
448    console.error("getTotalSizeSync failed with error:" + JSON.stringify(error));
449  }
450  ```
451
452## storageStatistics.getFreeSize<sup>9+</sup>
453
454getFreeSize(): Promise&lt;number&gt;
455
456Obtains the available space of the built-in storage, in bytes. This API uses a promise to return the result.
457
458**Required permissions**: ohos.permission.STORAGE_MANAGER
459
460**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
461
462**System API**: This is a system API.
463
464**Return value**
465
466  | Type                  | Description              |
467  | --------------------- | ------------------ |
468  | Promise&lt;number&gt; | Promise used to return the available space of the built-in storage obtained.|
469
470**Error codes**
471
472For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
473
474| ID| Error Message|
475| -------- | -------- |
476| 201 | Permission verification failed. |
477| 202 | The caller is not a system application. |
478| 401 | The input parameter is invalid. |
479| 13600001 | IPC error. |
480| 13900042 | Unknown error. |
481
482**Example**
483
484  ```ts
485  import { BusinessError } from '@ohos.base';
486  storageStatistics.getFreeSize().then((number: number) => {
487    console.info("getFreeSize successfully:" + JSON.stringify(number));
488  }).catch((err: BusinessError) => {
489    console.error("getFreeSize failed with error:" + JSON.stringify(err));
490  });
491  ```
492
493## storageStatistics.getFreeSize<sup>9+</sup>
494
495getFreeSize(callback: AsyncCallback&lt;number&gt;): void
496
497Obtains the available space of the built-in storage, in bytes. This API uses an asynchronous callback to return the result.
498
499**Required permissions**: ohos.permission.STORAGE_MANAGER
500
501**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
502
503**System API**: This is a system API.
504
505**Parameters**
506
507  | Name   | Type                                 | Mandatory| Description                      |
508  | -------- | ------------------------------------ | ---- | ------------------------- |
509  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the available space of the built-in storage obtained.|
510
511**Error codes**
512
513For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
514
515| ID| Error Message|
516| -------- | -------- |
517| 201 | Permission verification failed. |
518| 202 | The caller is not a system application. |
519| 401 | The input parameter is invalid. |
520| 13600001 | IPC error. |
521| 13900042 | Unknown error. |
522
523**Example**
524
525  ```ts
526  import { BusinessError } from '@ohos.base';
527  storageStatistics.getFreeSize((error: BusinessError, number: number) => {
528    if (error) {
529      console.error("getFreeSize failed with error:" + JSON.stringify(error));
530    } else {
531      // Do something.
532      console.info("getFreeSize successfully:" + number);
533    }
534  });
535  ```
536
537## storageStatistics.getFreeSizeSync<sup>10+</sup>
538
539getFreeSizeSync(): number
540
541Obtains the available space of the built-in storage, in bytes. This API returns the result synchronously.
542
543**Required permissions**: ohos.permission.STORAGE_MANAGER
544
545**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
546
547**System API**: This is a system API.
548
549**Return value**
550
551  | Type                  | Description              |
552  | --------------------- | ------------------ |
553  | number | Available space of the built-in storage obtained.|
554
555**Error codes**
556
557For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
558
559| ID| Error Message|
560| -------- | -------- |
561| 201 | Permission verification failed. |
562| 202 | The caller is not a system application. |
563| 401 | The input parameter is invalid. |
564| 13600001 | IPC error. |
565| 13900042 | Unknown error. |
566
567**Example**
568
569  ```ts
570  import { BusinessError } from '@ohos.base';
571  try {
572    let number = storageStatistics.getFreeSizeSync();
573    console.info("getFreeSizeSync successfully:" + JSON.stringify(number));
574  } catch (err) {
575    let error: BusinessError = err as BusinessError;
576    console.error("getFreeSizeSync failed with error:" + JSON.stringify(error));
577  }
578  ```
579
580## storageStatistics.getSystemSize<sup>9+</sup>
581
582getSystemSize(): Promise&lt;number&gt;
583
584Obtains the system data size, in bytes. This API uses a promise to return the result.
585
586**Required permissions**: ohos.permission.STORAGE_MANAGER
587
588**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
589
590**System API**: This is a system API.
591
592**Return value**
593
594  | Type                 | Description            |
595  | --------------------- | ---------------- |
596  | Promise&lt;number&gt; | Promise used to return the system data size obtained.|
597
598**Error codes**
599
600For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
601
602| ID| Error Message|
603| -------- | -------- |
604| 201 | Permission verification failed. |
605| 202 | The caller is not a system application. |
606| 401 | The input parameter is invalid. |
607| 13600001 | IPC error. |
608| 13900042 | Unknown error. |
609
610**Example**
611
612  ```ts
613  import { BusinessError } from '@ohos.base';
614  storageStatistics.getSystemSize().then((number: number) => {
615    console.info("getSystemSize successfully:" + number);
616  }).catch((err: BusinessError) => {
617    console.error("getSystemSize failed with error:" + JSON.stringify(err));
618  });
619  ```
620
621## storageStatistics.getSystemSize<sup>9+</sup>
622
623getSystemSize(callback: AsyncCallback&lt;number&gt;): void
624
625Obtains the system data size, in bytes. This API uses an asynchronous callback to return the result.
626
627**Required permissions**: ohos.permission.STORAGE_MANAGER
628
629**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
630
631**System API**: This is a system API.
632
633**Parameters**
634
635  | Name    | Type                                | Mandatory| Description                      |
636  | ---------- | ------------------------------------ | ---- | -------------------------- |
637  | callback   |  AsyncCallback&lt;number&gt;         | Yes  | Callback invoked to return the system data size obtained.|
638
639**Error codes**
640
641For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
642
643| ID| Error Message|
644| -------- | -------- |
645| 201 | Permission verification failed. |
646| 202 | The caller is not a system application. |
647| 401 | The input parameter is invalid. |
648| 13600001 | IPC error. |
649| 13900042 | Unknown error. |
650
651**Example**
652
653  ```ts
654  import { BusinessError } from '@ohos.base';
655  storageStatistics.getSystemSize((error: BusinessError, number: number) => {
656    if (error) {
657      console.error("getSystemSize failed with error:" + JSON.stringify(error));
658    } else {
659      // Do something.
660      console.info("getSystemSize successfully:" + number);
661    }
662  });
663  ```
664
665## storageStatistics.getUserStorageStats<sup>9+</sup>
666
667getUserStorageStats(): Promise&lt;StorageStats&gt;
668
669Obtains the storage statistics of this user, in bytes. This API uses a promise to return the result.
670
671**Required permissions**: ohos.permission.STORAGE_MANAGER
672
673**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
674
675**System API**: This is a system API.
676
677**Return value**
678
679  | Type                 | Description            |
680  | --------------------- | ---------------- |
681| Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the storage statistics obtained. |
682
683**Error codes**
684
685For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
686
687| ID| Error Message|
688| -------- | -------- |
689| 201 | Permission verification failed. |
690| 202 | The caller is not a system application. |
691| 401 | The input parameter is invalid. |
692| 13600001 | IPC error. |
693| 13900042 | Unknown error. |
694
695**Example**
696
697  ```ts
698  import { BusinessError } from '@ohos.base';
699  storageStatistics.getUserStorageStats().then((storageStats: storageStatistics.StorageStats) => {
700    console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
701  }).catch((err: BusinessError) => {
702    console.error("getUserStorageStats failed with error:" + JSON.stringify(err));
703  });
704  ```
705
706## storageStatistics.getUserStorageStats<sup>9+</sup>
707
708getUserStorageStats(callback: AsyncCallback&lt;StorageStats&gt;): void
709
710Obtains the storage statistics of this user, in bytes. This API uses an asynchronous callback to return the result.
711
712**Required permissions**: ohos.permission.STORAGE_MANAGER
713
714**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
715
716**System API**: This is a system API.
717
718**Parameters**
719
720  | Name    | Type                                | Mandatory| Description                      |
721  | ---------- | ------------------------------------ | ---- | -------------------------- |
722| callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback invoked to return the storage statistics obtained. |
723
724**Error codes**
725
726For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
727
728| ID| Error Message|
729| -------- | -------- |
730| 201 | Permission verification failed. |
731| 202 | The caller is not a system application. |
732| 401 | The input parameter is invalid. |
733| 13600001 | IPC error. |
734| 13900042 | Unknown error. |
735
736**Example**
737
738  ```ts
739  import { BusinessError } from '@ohos.base';
740  storageStatistics.getUserStorageStats((error: BusinessError, storageStats: storageStatistics.StorageStats) => {
741    if (error) {
742      console.error("getUserStorageStats failed with error:" + JSON.stringify(error));
743    } else {
744      // Do something.
745      console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
746    }
747  });
748  ```
749
750## storageStatistics.getUserStorageStats<sup>9+</sup>
751
752getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
753
754Obtains the storage statistics of the specified user, in bytes. This API uses a promise to return the result.
755
756**Required permissions**: ohos.permission.STORAGE_MANAGER
757
758**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
759
760**System API**: This is a system API.
761
762**Parameters**
763
764  | Name    | Type  | Mandatory| Description|
765  | ---------- | ------ | ---- | ---- |
766  | userId | number | Yes  | User ID|
767
768**Return value**
769
770  | Type                 | Description            |
771  | --------------------- | ---------------- |
772  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the storage statistics obtained.|
773
774**Error codes**
775
776For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
777
778| ID| Error Message|
779| -------- | -------- |
780| 201 | Permission verification failed. |
781| 202 | The caller is not a system application. |
782| 401 | The input parameter is invalid. |
783| 13600001 | IPC error. |
784| 13600009 | User if out of range. |
785| 13900042 | Unknown error. |
786
787**Example**
788
789  ```ts
790  import { BusinessError } from '@ohos.base';
791  let userId: number = 100;
792  storageStatistics.getUserStorageStats(userId).then((storageStats: storageStatistics.StorageStats) => {
793    console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
794  }).catch((err: BusinessError) => {
795    console.error("getUserStorageStats failed with error:" + JSON.stringify(err));
796  });
797  ```
798
799## storageStatistics.getUserStorageStats<sup>9+</sup>
800
801getUserStorageStats(userId: number, callback: AsyncCallback&lt;StorageStats&gt;): void
802
803Obtains the storage statistics of the specified user, in bytes. This API uses an asynchronous callback to return the result.
804
805**Required permissions**: ohos.permission.STORAGE_MANAGER
806
807**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
808
809**System API**: This is a system API.
810
811**Parameters**
812
813  | Name    | Type                                | Mandatory| Description                      |
814  | ---------- | ------------------------------------ | ---- | -------------------------- |
815  | userId | number                               | Yes  | User ID|
816  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback invoked to return the storage statistics obtained.|
817
818**Error codes**
819
820For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
821
822| ID| Error Message|
823| -------- | -------- |
824| 201 | Permission verification failed. |
825| 202 | The caller is not a system application. |
826| 401 | The input parameter is invalid. |
827| 13600001 | IPC error. |
828| 13600009 | User if out of range. |
829| 13900042 | Unknown error. |
830
831**Example**
832
833  ```ts
834  import { BusinessError } from '@ohos.base';
835  let userId: number = 100;
836  storageStatistics.getUserStorageStats(userId, (error: BusinessError, storageStats: storageStatistics.StorageStats) => {
837    if (error) {
838      console.error("getUserStorageStats failed with error:" + JSON.stringify(error));
839    } else {
840      // Do something.
841      console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
842    }
843  });
844  ```
845
846## StorageStats<sup>9+</sup>
847
848**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
849
850**System API**: This is a system API.
851
852| Name     | Type  | Readable | Writable | Description          |
853| --------- | ------ | ---- | ----- | -------------- |
854| total   | number | Yes| No| Total space of the built-in storage, in bytes.   |
855| audio | number  |Yes| No| Size of the audio data, in bytes. |
856| video  | number | Yes| No| Size of the video data, in bytes.|
857| image   | number | Yes| No| Size of the image data, in bytes.  |
858| file | number | Yes| No| Size of files, in bytes. |
859| app  | number | Yes| No| Size of application data, in bytes.|
860