1# @ohos.file.storageStatistics (应用空间统计)(系统接口)
2
3该模块提供空间查询相关的常用功能:包括对内外卡的空间查询,对应用分类数据统计的查询,对应用数据的查询等。
4
5> **说明:**
6>
7> - 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.file.storageStatistics (应用空间统计)](js-apis-file-storage-statistics.md)。
9
10## 导入模块
11
12```ts
13import storageStatistics from "@ohos.file.storageStatistics";
14```
15
16## storageStatistics.getTotalSizeOfVolume
17
18getTotalSizeOfVolume(volumeUuid: string): Promise<number>
19
20异步获取外置存储设备中指定卷设备的总空间大小(单位为Byte),以Promise方式返回。
21
22**需要权限**:ohos.permission.STORAGE_MANAGER
23
24**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
25
26**系统接口:** 该接口为系统接口。
27
28**参数:**
29
30  | 参数名     | 类型   | 必填 | 说明 |
31  | ---------- | ------ | ---- | ---- |
32  | volumeUuid | string | 是   | 卷设备uuid |
33
34**返回值:**
35
36  | 类型                  | 说明             |
37  | --------------------- | ---------------- |
38  | Promise<number> | Promise对象,返回指定卷设备的总空间大小(单位为Byte) |
39
40**错误码:**
41
42以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
43
44| 错误码ID | 错误信息 |
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**示例:**
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
74异步获取外置存储设备中指定卷设备的总空间大小(单位为Byte),以callback方式返回。
75
76**需要权限**:ohos.permission.STORAGE_MANAGER
77
78**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
79
80**系统接口:** 该接口为系统接口。
81
82**参数:**
83
84  | 参数名     | 类型                                 | 必填 | 说明                       |
85  | ---------- | ------------------------------------ | ---- | -------------------------- |
86  | volumeUuid | string                               | 是   | 卷设备uuid                       |
87  | callback   | AsyncCallback&lt;number&gt;          | 是   | 获取指定卷设备总空间之后的回调 |
88
89**错误码:**
90
91以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
92
93| 错误码ID | 错误信息 |
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**示例:**
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
126异步获取外置存储设备中指定卷设备的可用空间大小(单位为Byte),以Promise方式返回。
127
128**需要权限**:ohos.permission.STORAGE_MANAGER
129
130**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
131
132**系统接口:** 该接口为系统接口。
133
134**参数:**
135
136  | 参数名     | 类型   | 必填 | 说明 |
137  | ---------- | ------ | ---- | ---- |
138  | volumeUuid | string | 是   | 卷设备uuid |
139
140**返回值:**
141
142  | 类型                  | 说明               |
143  | --------------------- | ------------------ |
144  | Promise&lt;number&gt; | Promise对象,返回指定卷的可用空间大小(单位为Byte) |
145
146**错误码:**
147
148以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
149
150| 错误码ID | 错误信息 |
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**示例:**
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
180异步获取外置存储设备中指定卷设备的可用空间大小(单位为Byte),以callback方式返回。
181
182**需要权限**:ohos.permission.STORAGE_MANAGER
183
184**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
185
186**系统接口:** 该接口为系统接口。
187
188**参数:**
189
190  | 参数名     | 类型                                 | 必填 | 说明                         |
191  | ---------- | ------------------------------------ | ---- | ---------------------------- |
192  | volumeUuid | string                               | 是   | 卷设备uuid                         |
193  | callback   | AsyncCallback&lt;number&gt;          | 是   | 获取指定卷可用空间之后的回调 |
194
195**错误码:**
196
197以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
198
199| 错误码ID | 错误信息 |
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**示例:**
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
232异步获取应用存储数据的空间大小(单位为Byte),以Promise方式返回。
233
234**需要权限**:ohos.permission.STORAGE_MANAGER
235
236**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
237
238**系统接口:** 该接口为系统接口。
239
240**参数:**
241
242  | 参数名      | 类型   | 必填 | 说明     |
243  | ----------- | ------ | ---- | -------- |
244  | packageName | string | 是   | 应用包名 |
245  | index<sup>12+</sup> | number | 否   | 分身应用的索引号,默认值为0(表示未分身的主应用)。分身应用索引号在分身创建时默认占用从1开始且当前未被占用的最小索引号,并赋值给该应用的[BundleResourceInfo](../apis-ability-kit/js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo)的appIndex属性,后续可以通过调用[getBundleResourceInfo](../apis-ability-kit/js-apis-bundleResourceManager-sys.md#bundleresourcemanagergetbundleresourceinfo12)接口获得。|
246
247**返回值:**
248
249  | 类型                                       | 说明                       |
250  | ------------------------------------------ | -------------------------- |
251  | Promise&lt;[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)&gt; | Promise对象,返回指定卷上的应用存储数据的空间大小(单位为Byte) |
252
253**错误码:**
254
255以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
256
257| 错误码ID | 错误信息 |
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**示例:**
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
298异步获取应用存储数据的空间大小(单位为Byte),以callback方式返回。
299
300**需要权限**:ohos.permission.STORAGE_MANAGER
301
302**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
303
304**系统接口:** 该接口为系统接口。
305
306**参数:**
307
308  | 参数名   | 类型                                                      | 必填 | 说明                                 |
309  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
310  | packageName | string | 是   | 应用包名 |
311  | callback | AsyncCallback&lt;[Bundlestats](js-apis-file-storage-statistics.md#bundlestats9)&gt; | 是   | 获取指定卷上的应用存储数据的空间大小之后的回调 |
312  | index<sup>12+</sup> | number | 否   | 分身应用的索引号,默认值为0(表示未分身的主应用)。分身应用索引号在分身创建时默认占用从1开始且当前未被占用的最小索引号,并赋值给该应用的[BundleResourceInfo](../apis-ability-kit/js-apis-bundleManager-BundleResourceInfo-sys.md#bundleresourceinfo)的appIndex属性,后续可以通过调用[getBundleResourceInfo](../apis-ability-kit/js-apis-bundleResourceManager-sys.md#bundleresourcemanagergetbundleresourceinfo12)接口获得。|
313
314**错误码:**
315
316以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
317
318| 错误码ID | 错误信息 |
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**示例:**
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
361获取内置存储的总空间大小(单位为Byte),以Promise方式返回。
362
363**需要权限**:ohos.permission.STORAGE_MANAGER
364
365**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
366
367**系统接口:** 该接口为系统接口。
368
369**返回值:**
370
371  | 类型                   | 说明               |
372  | --------------------- | ------------------ |
373  | Promise&lt;number&gt; | Promise对象,返回内置存储的总空间大小(单位为Byte)   |
374
375**错误码:**
376
377以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
378
379| 错误码ID | 错误信息 |
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**示例:**
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
402获取内置存储的总空间大小(单位为Byte),以callback方式返回。
403
404**需要权限**:ohos.permission.STORAGE_MANAGER
405
406**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
407
408**系统接口:** 该接口为系统接口。
409
410**参数:**
411
412  | 参数名    | 类型                                  | 必填  | 说明                     |
413  | -------- | ------------------------------------ | ---- | ------------------------ |
414  | callback | AsyncCallback&lt;number&gt;          | 是   | 获取内置存储的总空间大小之后的回调 |
415
416**错误码:**
417
418以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
419
420| 错误码ID | 错误信息 |
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**示例:**
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
446同步获取内置存储的总空间大小(单位为Byte)。
447
448**需要权限**:ohos.permission.STORAGE_MANAGER
449
450**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
451
452**系统接口:** 该接口为系统接口。
453
454**返回值:**
455
456  | 类型                   | 说明               |
457  | --------------------- | ------------------ |
458  | number | 返回内置存储的总空间大小(单位为Byte)   |
459
460**错误码:**
461
462以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
463
464| 错误码ID | 错误信息 |
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**示例:**
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
489获取内置存储的可用空间大小(单位为Byte),以Promise方式返回。
490
491**需要权限**:ohos.permission.STORAGE_MANAGER
492
493**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
494
495**系统接口:** 该接口为系统接口。
496
497**返回值:**
498
499  | 类型                   | 说明               |
500  | --------------------- | ------------------ |
501  | Promise&lt;number&gt; | Promise对象,返回内置存储的可用空间大小(单位为Byte) |
502
503**错误码:**
504
505以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
506
507| 错误码ID | 错误信息 |
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**示例:**
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
530获取内置存储的可用空间大小(单位为Byte),以callback方式返回。
531
532**需要权限**:ohos.permission.STORAGE_MANAGER
533
534**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
535
536**系统接口:** 该接口为系统接口。
537
538**参数:**
539
540  | 参数名    | 类型                                  | 必填 | 说明                       |
541  | -------- | ------------------------------------ | ---- | ------------------------- |
542  | callback | AsyncCallback&lt;number&gt;          | 是   | 获取内置存储的可用空间大小之后的回调 |
543
544**错误码:**
545
546以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
547
548| 错误码ID | 错误信息 |
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**示例:**
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
574同步获取内置存储的可用空间大小(单位为Byte)。
575
576**需要权限**:ohos.permission.STORAGE_MANAGER
577
578**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
579
580**系统接口:** 该接口为系统接口。
581
582**返回值:**
583
584  | 类型                   | 说明               |
585  | --------------------- | ------------------ |
586  | number | 返回内置存储的可用空间大小(单位为Byte) |
587
588**错误码:**
589
590以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
591
592| 错误码ID | 错误信息 |
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**示例:**
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
617异步获取系统数据的空间大小(单位为Byte),以Promise方式返回。
618
619**需要权限**:ohos.permission.STORAGE_MANAGER
620
621**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
622
623**系统接口:** 该接口为系统接口。
624
625**返回值:**
626
627  | 类型                  | 说明             |
628  | --------------------- | ---------------- |
629  | Promise&lt;number&gt; | Promise对象,返回系统数据的空间大小(单位为Byte) |
630
631**错误码:**
632
633以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
634
635| 错误码ID | 错误信息 |
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**示例:**
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
658异步获取系统数据的空间大小(单位为Byte),以callback方式返回。
659
660**需要权限**:ohos.permission.STORAGE_MANAGER
661
662**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
663
664**系统接口:** 该接口为系统接口。
665
666**参数:**
667
668  | 参数名     | 类型                                 | 必填 | 说明                       |
669  | ---------- | ------------------------------------ | ---- | -------------------------- |
670  | callback   |  AsyncCallback&lt;number&gt;         | 是   | 获取系统数据的空间大小之后的回调 |
671
672**错误码:**
673
674以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
675
676| 错误码ID | 错误信息 |
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**示例:**
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
702异步获取当前用户各类别存储空间大小(单位为Byte),以Promise方式返回。
703
704**需要权限**:ohos.permission.STORAGE_MANAGER
705
706**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
707
708**系统接口:** 该接口为系统接口。
709
710**返回值:**
711
712  | 类型                  | 说明             |
713  | --------------------- | ---------------- |
714  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise对象,返回当前用户各类别存储空间大小(单位为Byte) |
715
716**错误码:**
717
718以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
719
720| 错误码ID | 错误信息 |
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**示例:**
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
743异步获取当前用户各类别存储空间大小(单位为Byte),以callback方式返回。
744
745**需要权限**:ohos.permission.STORAGE_MANAGER
746
747**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
748
749**系统接口:** 该接口为系统接口。
750
751**参数:**
752
753  | 参数名     | 类型                                 | 必填 | 说明                       |
754  | ---------- | ------------------------------------ | ---- | -------------------------- |
755  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | 是   | 返回用户各类别存储空间大小之后的回调 |
756
757**错误码:**
758
759以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
760
761| 错误码ID | 错误信息 |
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**示例:**
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
787异步获取指定用户各类别存储空间大小(单位为Byte),以Promise方式返回。
788
789**需要权限**:ohos.permission.STORAGE_MANAGER
790
791**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
792
793**系统接口:** 该接口为系统接口。
794
795**参数:**
796
797  | 参数名     | 类型   | 必填 | 说明 |
798  | ---------- | ------ | ---- | ---- |
799  | userId | number | 是   | 用户id|
800
801**返回值:**
802
803  | 类型                  | 说明             |
804  | --------------------- | ---------------- |
805  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise对象,返回指定用户各类别存储空间大小(单位为Byte) |
806
807**错误码:**
808
809以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
810
811| 错误码ID | 错误信息 |
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**示例:**
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
836异步获取指定用户各类别存储空间大小(单位为Byte),以callback方式返回。
837
838**需要权限**:ohos.permission.STORAGE_MANAGER
839
840**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
841
842**系统接口:** 该接口为系统接口。
843
844**参数:**
845
846  | 参数名     | 类型                                 | 必填 | 说明                       |
847  | ---------- | ------------------------------------ | ---- | -------------------------- |
848  | userId | number                               | 是   | 用户id |
849  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | 是   | 返回指定用户各类别存储空间大小之后的回调 |
850
851**错误码:**
852
853以下错误码的详细介绍请参见[文件管理错误码](errorcode-filemanagement.md)。
854
855| 错误码ID | 错误信息 |
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**示例:**
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**系统能力**:SystemCapability.FileManagement.StorageService.SpatialStatistics
882
883**系统接口:** 该接口为系统接口。
884
885| 名称      | 类型   | 只读  | 可写  | 说明           |
886| --------- | ------ | ---- | ----- | -------------- |
887| total   | number | 是 | 否 | 内置存储总空间大小(单位为Byte)    |
888| audio | number  |是 | 否 | 音频数据大小 (单位为Byte)  |
889| video  | number | 是 | 否 | 视频数据大小(单位为Byte) |
890| image   | number | 是 | 否 | 图像数据大小 (单位为Byte)   |
891| file | number | 是 | 否 | 文件数据大小 (单位为Byte)  |
892| app  | number | 是 | 否 | 应用数据大小(单位为Byte) |
893