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