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