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.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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
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 used 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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
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 used 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. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
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, index?: number): 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  | index<sup>12+</sup> | number | No  | Index of an application clone. The default value is **0**, which indicates the application itself. When an application clone is created, an index is assigned from 1 sequentially to **appIndex** of [BundleResourceInfo](../apis-ability-kit/js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo). The index can be obtained by [getBundleResourceInfo](../apis-ability-kit/js-apis-bundleResourceManager-sys.md#bundleresourcemanagergetbundleresourceinfo12).|
246
247**Return value**
248
249  | Type                                      | Description                      |
250  | ------------------------------------------ | -------------------------- |
251  | Promise&lt;[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)&gt; | Promise used to return the application storage space obtained.|
252
253**Error codes**
254
255For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
256
257| ID| Error Message|
258| -------- | -------- |
259| 201 | Permission verification failed. |
260| 202 | The caller is not a system application. |
261| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
262| 13600001 | IPC error. |
263| 13600008 | No such object. |
264| 13900042 | Unknown error. |
265
266**Example**
267
268  ```ts
269  import bundleResourceManager from '@ohos.bundle.bundleResourceManager';
270  import storageStatistics from "@ohos.file.storageStatistics";
271  import { BusinessError } from '@ohos.base';
272  import { hilog } from '@kit.PerformanceAnalysisKit';
273
274  let bundleName = "com.example.myapplication";
275  let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
276  try {
277    let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags);
278    hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label));
279
280    let packageName:string = bundleName;
281    let index:number = resourceInfo.appIndex;
282    storageStatistics.getBundleStats(packageName, index).then((BundleStats: storageStatistics.BundleStats) => {
283      hilog.info(0x0000, 'testTag', 'getBundleStats successfully. BundleStats: %{public}s', JSON.stringify(BundleStats));
284    }).catch((err: BusinessError) => {
285      hilog.error(0x0000, 'testTag', 'getBundleStats failed with error: %{public}s', JSON.stringify(err));
286    });
287
288  } catch (err) {
289    let message = (err as BusinessError).message;
290    hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed with error: %{public}s', message);
291  }
292  ```
293
294## storageStatistics.getBundleStats<sup>9+</sup>
295
296getBundleStats(packageName: string,  callback: AsyncCallback&lt;BundleStats&gt;, index?: number): void
297
298Obtains the storage space of an application, in bytes. This API uses an asynchronous callback to return the result.
299
300**Required permissions**: ohos.permission.STORAGE_MANAGER
301
302**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
303
304**System API**: This is a system API.
305
306**Parameters**
307
308  | Name  | Type                                                     | Mandatory| Description                                |
309  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
310  | packageName | string | Yes  | Bundle name.|
311  | callback | AsyncCallback&lt;[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)&gt; | Yes  | Callback used to return the application storage space obtained.|
312  | index<sup>12+</sup> | number | No  | Index of an application clone. The default value is **0**, which indicates the application itself. When an application clone is created, an index is assigned from 1 sequentially to **appIndex** of [BundleResourceInfo](../apis-ability-kit/js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo). The index can be obtained by [getBundleResourceInfo](../apis-ability-kit/js-apis-bundleResourceManager-sys.md#bundleresourcemanagergetbundleresourceinfo12).|
313
314**Error codes**
315
316For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
317
318| ID| Error Message|
319| -------- | -------- |
320| 201 | Permission verification failed. |
321| 202 | The caller is not a system application. |
322| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
323| 13600001 | IPC error. |
324| 13600008 | No such object. |
325| 13900042 | Unknown error. |
326
327**Example**
328
329  ```ts
330  import bundleResourceManager from '@ohos.bundle.bundleResourceManager';
331  import storageStatistics from "@ohos.file.storageStatistics";
332  import { BusinessError } from '@ohos.base';
333  import { hilog } from '@kit.PerformanceAnalysisKit';
334
335  let bundleName = "com.example.myapplication";
336  let bundleFlags = bundleResourceManager.ResourceFlag.GET_RESOURCE_INFO_ALL;
337  try {
338    let resourceInfo = bundleResourceManager.getBundleResourceInfo(bundleName, bundleFlags);
339    hilog.info(0x0000, 'testTag', 'getBundleResourceInfo successfully. Data label: %{public}s', JSON.stringify(resourceInfo.label));
340
341    let packageName:string = bundleName;
342    let index:number = resourceInfo.appIndex;
343    storageStatistics.getBundleStats(packageName, (err: BusinessError, BundleStats: storageStatistics.BundleStats) => {
344      if (err) {
345        hilog.error(0x0000, 'testTag', 'getBundleStats failed with error: %{public}s', JSON.stringify(err));
346      } else {
347        hilog.info(0x0000, 'testTag', 'getBundleStats successfully. BundleStats: %{public}s', JSON.stringify(BundleStats));
348      }
349    }, index);
350
351  } catch (err) {
352    let message = (err as BusinessError).message;
353    hilog.error(0x0000, 'testTag', 'getBundleResourceInfo failed: %{public}s', message);
354  }
355  ```
356
357## storageStatistics.getTotalSize<sup>9+</sup>
358
359getTotalSize(): Promise&lt;number&gt;
360
361Obtains the total space of the built-in storage, in bytes. This API uses a promise to return the result.
362
363**Required permissions**: ohos.permission.STORAGE_MANAGER
364
365**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
366
367**System API**: This is a system API.
368
369**Return value**
370
371  | Type                  | Description              |
372  | --------------------- | ------------------ |
373  | Promise&lt;number&gt; | Promise used to return the total built-in storage space obtained.  |
374
375**Error codes**
376
377For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
378
379| ID| Error Message|
380| -------- | -------- |
381| 201 | Permission verification failed. |
382| 202 | The caller is not a system application. |
383| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
384| 13600001 | IPC error. |
385| 13900042 | Unknown error. |
386
387**Example**
388
389  ```ts
390  import { BusinessError } from '@ohos.base';
391  storageStatistics.getTotalSize().then((number: number) => {
392    console.info("getTotalSize successfully:" + JSON.stringify(number));
393  }).catch((err: BusinessError) => {
394    console.error("getTotalSize failed with error:"+ JSON.stringify(err));
395  });
396  ```
397
398## storageStatistics.getTotalSize<sup>9+</sup>
399
400getTotalSize(callback: AsyncCallback&lt;number&gt;): void
401
402Obtains the total space of the built-in storage, in bytes. This API uses an asynchronous callback to return the result.
403
404**Required permissions**: ohos.permission.STORAGE_MANAGER
405
406**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
407
408**System API**: This is a system API.
409
410**Parameters**
411
412  | Name   | Type                                 | Mandatory | Description                    |
413  | -------- | ------------------------------------ | ---- | ------------------------ |
414  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback used to return the built-in storage space obtained.|
415
416**Error codes**
417
418For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
419
420| ID| Error Message|
421| -------- | -------- |
422| 201 | Permission verification failed. |
423| 202 | The caller is not a system application. |
424| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
425| 13600001 | IPC error. |
426| 13900042 | Unknown error. |
427
428**Example**
429
430  ```ts
431  import { BusinessError } from '@ohos.base';
432  storageStatistics.getTotalSize((error: BusinessError, number: number) => {
433    if (error) {
434      console.error("getTotalSize failed with error:" + JSON.stringify(error));
435    } else {
436      // Do something.
437      console.info("getTotalSize successfully:" + number);
438    }
439  });
440  ```
441
442## storageStatistics.getTotalSizeSync<sup>10+</sup>
443
444getTotalSizeSync(): number
445
446Obtains the total space of the built-in storage, in bytes. This API returns the result synchronously.
447
448**Required permissions**: ohos.permission.STORAGE_MANAGER
449
450**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
451
452**System API**: This is a system API.
453
454**Return value**
455
456  | Type                  | Description              |
457  | --------------------- | ------------------ |
458  | number | Built-in storage space obtained.  |
459
460**Error codes**
461
462For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
463
464| ID| Error Message|
465| -------- | -------- |
466| 201 | Permission verification failed. |
467| 202 | The caller is not a system application. |
468| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
469| 13600001 | IPC error. |
470| 13900042 | Unknown error. |
471
472**Example**
473
474  ```ts
475  import { BusinessError } from '@ohos.base';
476  try {
477    let number = storageStatistics.getTotalSizeSync();
478    console.info("getTotalSizeSync successfully:" + JSON.stringify(number));
479  } catch (err) {
480    let error: BusinessError = err as BusinessError;
481    console.error("getTotalSizeSync failed with error:" + JSON.stringify(error));
482  }
483  ```
484
485## storageStatistics.getFreeSize<sup>9+</sup>
486
487getFreeSize(): Promise&lt;number&gt;
488
489Obtains the available space of the built-in storage, in bytes. This API uses a promise to return the result.
490
491**Required permissions**: ohos.permission.STORAGE_MANAGER
492
493**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
494
495**System API**: This is a system API.
496
497**Return value**
498
499  | Type                  | Description              |
500  | --------------------- | ------------------ |
501  | Promise&lt;number&gt; | Promise used to return the available space of the built-in storage obtained.|
502
503**Error codes**
504
505For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
506
507| ID| Error Message|
508| -------- | -------- |
509| 201 | Permission verification failed. |
510| 202 | The caller is not a system application. |
511| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
512| 13600001 | IPC error. |
513| 13900042 | Unknown error. |
514
515**Example**
516
517  ```ts
518  import { BusinessError } from '@ohos.base';
519  storageStatistics.getFreeSize().then((number: number) => {
520    console.info("getFreeSize successfully:" + JSON.stringify(number));
521  }).catch((err: BusinessError) => {
522    console.error("getFreeSize failed with error:" + JSON.stringify(err));
523  });
524  ```
525
526## storageStatistics.getFreeSize<sup>9+</sup>
527
528getFreeSize(callback: AsyncCallback&lt;number&gt;): void
529
530Obtains the available space of the built-in storage, in bytes. This API uses an asynchronous callback to return the result.
531
532**Required permissions**: ohos.permission.STORAGE_MANAGER
533
534**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
535
536**System API**: This is a system API.
537
538**Parameters**
539
540  | Name   | Type                                 | Mandatory| Description                      |
541  | -------- | ------------------------------------ | ---- | ------------------------- |
542  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback used to return the available space of the built-in storage obtained.|
543
544**Error codes**
545
546For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
547
548| ID| Error Message|
549| -------- | -------- |
550| 201 | Permission verification failed. |
551| 202 | The caller is not a system application. |
552| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
553| 13600001 | IPC error. |
554| 13900042 | Unknown error. |
555
556**Example**
557
558  ```ts
559  import { BusinessError } from '@ohos.base';
560  storageStatistics.getFreeSize((error: BusinessError, number: number) => {
561    if (error) {
562      console.error("getFreeSize failed with error:" + JSON.stringify(error));
563    } else {
564      // Do something.
565      console.info("getFreeSize successfully:" + number);
566    }
567  });
568  ```
569
570## storageStatistics.getFreeSizeSync<sup>10+</sup>
571
572getFreeSizeSync(): number
573
574Obtains the available space of the built-in storage, in bytes. This API returns the result synchronously.
575
576**Required permissions**: ohos.permission.STORAGE_MANAGER
577
578**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
579
580**System API**: This is a system API.
581
582**Return value**
583
584  | Type                  | Description              |
585  | --------------------- | ------------------ |
586  | number | Available space of the built-in storage obtained.|
587
588**Error codes**
589
590For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
591
592| ID| Error Message|
593| -------- | -------- |
594| 201 | Permission verification failed. |
595| 202 | The caller is not a system application. |
596| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
597| 13600001 | IPC error. |
598| 13900042 | Unknown error. |
599
600**Example**
601
602  ```ts
603  import { BusinessError } from '@ohos.base';
604  try {
605    let number = storageStatistics.getFreeSizeSync();
606    console.info("getFreeSizeSync successfully:" + JSON.stringify(number));
607  } catch (err) {
608    let error: BusinessError = err as BusinessError;
609    console.error("getFreeSizeSync failed with error:" + JSON.stringify(error));
610  }
611  ```
612
613## storageStatistics.getSystemSize<sup>9+</sup>
614
615getSystemSize(): Promise&lt;number&gt;
616
617Obtains the system data size, in bytes. This API uses a promise to return the result.
618
619**Required permissions**: ohos.permission.STORAGE_MANAGER
620
621**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
622
623**System API**: This is a system API.
624
625**Return value**
626
627  | Type                 | Description            |
628  | --------------------- | ---------------- |
629  | Promise&lt;number&gt; | Promise used to return the system data size obtained.|
630
631**Error codes**
632
633For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
634
635| ID| Error Message|
636| -------- | -------- |
637| 201 | Permission verification failed. |
638| 202 | The caller is not a system application. |
639| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
640| 13600001 | IPC error. |
641| 13900042 | Unknown error. |
642
643**Example**
644
645  ```ts
646  import { BusinessError } from '@ohos.base';
647  storageStatistics.getSystemSize().then((number: number) => {
648    console.info("getSystemSize successfully:" + number);
649  }).catch((err: BusinessError) => {
650    console.error("getSystemSize failed with error:" + JSON.stringify(err));
651  });
652  ```
653
654## storageStatistics.getSystemSize<sup>9+</sup>
655
656getSystemSize(callback: AsyncCallback&lt;number&gt;): void
657
658Obtains the system data size, in bytes. This API uses an asynchronous callback to return the result.
659
660**Required permissions**: ohos.permission.STORAGE_MANAGER
661
662**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
663
664**System API**: This is a system API.
665
666**Parameters**
667
668  | Name    | Type                                | Mandatory| Description                      |
669  | ---------- | ------------------------------------ | ---- | -------------------------- |
670  | callback   |  AsyncCallback&lt;number&gt;         | Yes  | Callback used to return the system data size obtained.|
671
672**Error codes**
673
674For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
675
676| ID| Error Message|
677| -------- | -------- |
678| 201 | Permission verification failed. |
679| 202 | The caller is not a system application. |
680| 401 | The input parameter is invalid. Possible causes: Mandatory parameters are left unspecified. |
681| 13600001 | IPC error. |
682| 13900042 | Unknown error. |
683
684**Example**
685
686  ```ts
687  import { BusinessError } from '@ohos.base';
688  storageStatistics.getSystemSize((error: BusinessError, number: number) => {
689    if (error) {
690      console.error("getSystemSize failed with error:" + JSON.stringify(error));
691    } else {
692      // Do something.
693      console.info("getSystemSize successfully:" + number);
694    }
695  });
696  ```
697
698## storageStatistics.getUserStorageStats<sup>9+</sup>
699
700getUserStorageStats(): Promise&lt;StorageStats&gt;
701
702Obtains the storage statistics of this user, in bytes. This API uses a promise to return the result.
703
704**Required permissions**: ohos.permission.STORAGE_MANAGER
705
706**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
707
708**System API**: This is a system API.
709
710**Return value**
711
712  | Type                 | Description            |
713  | --------------------- | ---------------- |
714| Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the storage statistics obtained. |
715
716**Error codes**
717
718For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
719
720| ID| Error Message|
721| -------- | -------- |
722| 201 | Permission verification failed. |
723| 202 | The caller is not a system application. |
724| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
725| 13600001 | IPC error. |
726| 13900042 | Unknown error. |
727
728**Example**
729
730  ```ts
731  import { BusinessError } from '@ohos.base';
732  storageStatistics.getUserStorageStats().then((storageStats: storageStatistics.StorageStats) => {
733    console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
734  }).catch((err: BusinessError) => {
735    console.error("getUserStorageStats failed with error:" + JSON.stringify(err));
736  });
737  ```
738
739## storageStatistics.getUserStorageStats<sup>9+</sup>
740
741getUserStorageStats(callback: AsyncCallback&lt;StorageStats&gt;): void
742
743Obtains the storage statistics of this user, in bytes. This API uses an asynchronous callback to return the result.
744
745**Required permissions**: ohos.permission.STORAGE_MANAGER
746
747**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
748
749**System API**: This is a system API.
750
751**Parameters**
752
753  | Name    | Type                                | Mandatory| Description                      |
754  | ---------- | ------------------------------------ | ---- | -------------------------- |
755  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback used to return the storage statistics obtained.|
756
757**Error codes**
758
759For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
760
761| ID| Error Message|
762| -------- | -------- |
763| 201 | Permission verification failed. |
764| 202 | The caller is not a system application. |
765| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
766| 13600001 | IPC error. |
767| 13900042 | Unknown error. |
768
769**Example**
770
771  ```ts
772  import { BusinessError } from '@ohos.base';
773  storageStatistics.getUserStorageStats((error: BusinessError, storageStats: storageStatistics.StorageStats) => {
774    if (error) {
775      console.error("getUserStorageStats failed with error:" + JSON.stringify(error));
776    } else {
777      // Do something.
778      console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
779    }
780  });
781  ```
782
783## storageStatistics.getUserStorageStats<sup>9+</sup>
784
785getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
786
787Obtains the storage statistics of the specified user, in bytes. This API uses a promise to return the result.
788
789**Required permissions**: ohos.permission.STORAGE_MANAGER
790
791**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
792
793**System API**: This is a system API.
794
795**Parameters**
796
797  | Name    | Type  | Mandatory| Description|
798  | ---------- | ------ | ---- | ---- |
799  | userId | number | Yes  | User ID|
800
801**Return value**
802
803  | Type                 | Description            |
804  | --------------------- | ---------------- |
805  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the storage statistics obtained.|
806
807**Error codes**
808
809For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
810
811| ID| Error Message|
812| -------- | -------- |
813| 201 | Permission verification failed. |
814| 202 | The caller is not a system application. |
815| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
816| 13600001 | IPC error. |
817| 13600009 | User if out of range. |
818| 13900042 | Unknown error. |
819
820**Example**
821
822  ```ts
823  import { BusinessError } from '@ohos.base';
824  let userId: number = 100;
825  storageStatistics.getUserStorageStats(userId).then((storageStats: storageStatistics.StorageStats) => {
826    console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
827  }).catch((err: BusinessError) => {
828    console.error("getUserStorageStats failed with error:" + JSON.stringify(err));
829  });
830  ```
831
832## storageStatistics.getUserStorageStats<sup>9+</sup>
833
834getUserStorageStats(userId: number, callback: AsyncCallback&lt;StorageStats&gt;): void
835
836Obtains the storage statistics of the specified user, in bytes. This API uses an asynchronous callback to return the result.
837
838**Required permissions**: ohos.permission.STORAGE_MANAGER
839
840**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
841
842**System API**: This is a system API.
843
844**Parameters**
845
846  | Name    | Type                                | Mandatory| Description                      |
847  | ---------- | ------------------------------------ | ---- | -------------------------- |
848  | userId | number                               | Yes  | User ID|
849  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback used to return the storage statistics obtained.|
850
851**Error codes**
852
853For details about the error codes, see [File Management Error Codes](errorcode-filemanagement.md).
854
855| ID| Error Message|
856| -------- | -------- |
857| 201 | Permission verification failed. |
858| 202 | The caller is not a system application. |
859| 401 | The input parameter is invalid. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. |
860| 13600001 | IPC error. |
861| 13600009 | User if out of range. |
862| 13900042 | Unknown error. |
863
864**Example**
865
866  ```ts
867  import { BusinessError } from '@ohos.base';
868  let userId: number = 100;
869  storageStatistics.getUserStorageStats(userId, (error: BusinessError, storageStats: storageStatistics.StorageStats) => {
870    if (error) {
871      console.error("getUserStorageStats failed with error:" + JSON.stringify(error));
872    } else {
873      // Do something.
874      console.info("getUserStorageStats successfully:" + JSON.stringify(storageStats));
875    }
876  });
877  ```
878
879## StorageStats<sup>9+</sup>
880
881**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
882
883**System API**: This is a system API.
884
885| Name     | Type  | Read-Only | Writable | Description          |
886| --------- | ------ | ---- | ----- | -------------- |
887| total   | number | Yes| No| Total space of the built-in storage, in bytes.   |
888| audio | number  |Yes| No| Size of the audio data, in bytes. |
889| video  | number | Yes| No| Size of the video data, in bytes.|
890| image   | number | Yes| No| Size of the image data, in bytes.  |
891| file | number | Yes| No| Size of files, in bytes. |
892| app  | number | Yes| No| Size of application data, in bytes.|
893