1# App 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**<br/> 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> - API version 9 is a canary version for trial use. The APIs of this version may be unstable. 9 10## Modules to Import 11 12```js 13import storageStatistics from "@ohos.storageStatistics"; 14``` 15 16## storageStatistics.getTotalSizeOfVolume 17 18getTotalSizeOfVolume(volumeUuid: string): Promise<number> 19 20Asynchronously obtains the total size of the specified volume. 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 27This is a system API and cannot be called by third-party applications. 28 29 30**Parameters** 31 32 | Name | Type | Mandatory| Description| 33 | ---------- | ------ | ---- | ---- | 34 | volumeUuid | string | Yes | UUID of the volume.| 35 36**Return value** 37 38 | Type | Description | 39 | --------------------- | ---------------- | 40 | Promise<number> | Promise used to return the total size of the volume.| 41 42**Example** 43 44 ```js 45 let uuid = ""; 46 storageStatistics.getTotalSizeOfVolume(uuid).then(function(number){ 47 console.info("getTotalSizeOfVolume successfully:"+ number); 48 }).catch(function(err){ 49 console.info("getTotalSizeOfVolume failed with error:"+ err); 50 }); 51 ``` 52 53## storageStatistics.getTotalSizeOfVolume 54 55getTotalSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):void 56 57Asynchronously obtains the total size of the specified volume. This API uses a callback to return the result. 58 59**Required permissions**: ohos.permission.STORAGE_MANAGER 60 61**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 62 63 64This is a system API and cannot be called by third-party applications. 65 66 67**Parameters** 68 69 | Name | Type | Mandatory| Description | 70 | ---------- | ------------------------------------ | ---- | -------------------------- | 71 | volumeUuid | string | Yes | UUID of the volume. | 72 | callback | callback:AsyncCallback<number> | Yes | Callback invoked to return the total size of the volume.| 73 74**Example** 75 76 ```js 77 let uuid = ""; 78 storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){ 79 // Do something. 80 console.info("getTotalSizeOfVolume successfully:"+ number); 81 }); 82 ``` 83 84## storageStatistics.getFreeSizeOfVolume 85 86getFreeSizeOfVolume(volumeUuid: string): Promise<number> 87 88Asynchronously obtains the available space of the specified volume. This API uses a promise to return the result. 89 90**Required permissions**: ohos.permission.STORAGE_MANAGER 91 92**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 93 94 95This is a system API and cannot be called by third-party applications. 96 97 98**Parameters** 99 100 | Name | Type | Mandatory| Description| 101 | ---------- | ------ | ---- | ---- | 102 | volumeUuid | string | Yes | UUID of the volume.| 103 104**Return value** 105 106 | Type | Description | 107 | --------------------- | ------------------ | 108 | Promise<number> | Promise used to return the available space of the volume.| 109 110**Example** 111 112 ```js 113 let uuid = ""; 114 storageStatistics.getFreeSizeOfVolume(uuid).then(function(number){ 115 console.info("getFreeSizeOfVolume successfully:"+ number); 116 }).catch(function(err){ 117 console.info("getFreeSizeOfVolume failed with error:"+ err); 118 }); 119 120 ``` 121 122## storageStatistics.getFreeSizeOfVolume 123 124getFreeSizeOfVolume(volumeUuid: string, callback:AsyncCallback<number>):void 125 126Asynchronously obtains the available space of the specified volume. This API uses a callback to return the result. 127 128**Required permissions**: ohos.permission.STORAGE_MANAGER 129 130**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 131 132 133This is a system API and cannot be called by third-party applications. 134 135 136**Parameters** 137 138 | Name | Type | Mandatory| Description | 139 | ---------- | ------------------------------------ | ---- | ---------------------------- | 140 | volumeUuid | string | Yes | UUID of the volume. | 141 | callback | callback:AsyncCallback<number> | Yes | Callback invoked to return the available space of the volume.| 142 143**Example** 144 145 ```js 146 let uuid = ""; 147 storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){ 148 // Do something. 149 console.info("getFreeSizeOfVolume successfully:"+ number); 150 }); 151 ``` 152 153## storageStatistics.getBundleStats<sup>9+</sup> 154 155getBundleStats(packageName: string): Promise<BundleStats> 156 157Asynchronously obtains space information of an application. This API uses a promise to return the result. 158 159**Required permissions**: ohos.permission.STORAGE_MANAGER 160 161**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 162 163 164This is a system API and cannot be called by third-party applications. 165 166 167**Parameters** 168 169 | Name | Type | Mandatory| Description | 170 | ----------- | ------ | ---- | -------- | 171 | packageName | string | Yes | Bundle name of the application.| 172 173**Return value** 174 175 | Type | Description | 176 | ------------------------------------------ | -------------------------- | 177 | Promise<[Bundlestats](#bundlestats)> | Promise used to return the space information obtained.| 178 179**Example** 180 181 ```js 182 let packageName = ""; 183 storageStatistics.getBundleStats(packageName).then(function(BundleStats){ 184 console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats)); 185 }).catch(function(err){ 186 console.info("getBundleStats failed with error:"+ err); 187 }); 188 ``` 189 190## storageStatistics.getBundleStats<sup>9+</sup> 191 192getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>): void 193 194Asynchronously obtains space information of an application. This API uses a callback to return the result. 195 196**Required permissions**: ohos.permission.STORAGE_MANAGER 197 198**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 199 200 201This is a system API and cannot be called by third-party applications. 202 203 204**Parameters** 205 206 | Name | Type | Mandatory| Description | 207 | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | 208 | packageName | string | Yes | Bundle name of the application.| 209 | callback | callback:AsyncCallback<[Bundlestats](#bundlestats)> | Yes | Callback invoked to return the space information obtained.| 210 211**Example** 212 213 ```js 214 let packageName = ""; 215 storageStatistics.getBundleStats(packageName, function(error, BundleStats){ 216 // Do something. 217 console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats)); 218 }); 219 ``` 220 221## storageStatistics.getCurrentBundleStats<sup>9+</sup> 222 223getCurrentBundleStats(): Promise<BundleStats> 224 225Asynchronously obtains space information of the current third-party application. This API uses a promise to return the result. 226 227**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 228 229**Return value** 230 231 | Type | Description | 232 | ------------------------------------------ | -------------------------- | 233 | Promise<[Bundlestats](#bundlestats)> | Promise used to return the space information obtained. | 234 235**Example** 236 237 ```js 238 let bundleStats = storageStatistics.getCurrentBundleStats(); 239 console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); 240 ``` 241 242## storageStatistics.getCurrentBundleStats<sup>9+</sup> 243 244getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void 245 246Asynchronously obtains space information of the current third-party application. This API uses a callback to return the result. 247 248**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 249 250**Parameters** 251 252 | Name | Type | Mandatory | Description | 253 | -------- | --------------------------------------------------------- | ---- | ------------------------------------ | 254 | callback | callback:AsyncCallback<[BundleStats](#bundlestats)> | Yes | Callback invoked to return the space information obtained. | 255 256**Example** 257 258 ```js 259 storageStatistics.getCurrentBundleStats(function(error, bundleStats){ 260 // Do something. 261 console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats)); 262 }); 263 ``` 264 265## BundleStats<sup>9+</sup> 266 267### Attributes 268 269**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 270 271 272This is a system API and cannot be called by third-party applications. 273 274| Name | Type | Description | 275| --------- | ------ | -------------- | 276| appSize | number | Size of the application. | 277| cacheSize | number | Cache size of the application. | 278| dataSize | number | Total data size of the application.| 279 280 281## storageStatistics.getTotalSize<sup>9+</sup> 282 283getTotalSize(): Promise<number> 284 285Obtains the total space of the built-in memory card. This API uses a promise to return the result. 286 287**Required permissions**: ohos.permission.STORAGE_MANAGER 288 289**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 290 291 292This is a system API and cannot be called by third-party applications. 293 294 295**Return value** 296 297 | Type | Description | 298 | --------------------- | ------------------ | 299 | Promise<number> | Promise used to return the total space of the built-in memory card. | 300 301**Example** 302 303 ```js 304 let number = storageStatistics.getTotalSize(); 305 console.info("getTotalSize successfully:"+ JSON.stringify(number)); 306 ``` 307 308## storageStatistics.getTotalSize<sup>9+</sup> 309 310getTotalSize(callback: AsyncCallback<number>): void 311 312Obtains the total space of the built-in memory card. This API uses a callback to return the result. 313 314**Required permissions**: ohos.permission.STORAGE_MANAGER 315 316**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 317 318 319This is a system API and cannot be called by third-party applications. 320 321 322**Parameters** 323 324 | Name | Type | Mandatory | Description | 325 | -------- | ------------------------------------ | ---- | ------------------------ | 326 | callback | callback:AsyncCallback<number> | Yes | Callback invoked to return the total space of the built-in memory card.| 327 328**Example** 329 330 ```js 331 storageStatistics.getTotalSize(function(error, number){ 332 // Do something. 333 console.info("getTotalSize successfully:"+ JSON.stringify(number)); 334 }); 335 ``` 336 337 338## storageStatistics.getFreeSize<sup>9+</sup> 339 340getFreeSize(): Promise<number> 341 342Obtains the available space of the built-in memory card. This API uses a promise to return the result. 343 344**Required permissions**: ohos.permission.STORAGE_MANAGER 345 346**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 347 348 349This is a system API and cannot be called by third-party applications. 350 351 352**Return value** 353 354 | Type | Description | 355 | --------------------- | ------------------ | 356 | Promise<number> | Promise used to return the available space of the built-in memory card.| 357 358**Example** 359 360 ```js 361 let number = storageStatistics.getFreeSize(); 362 console.info("getFreeSize successfully:"+ JSON.stringify(number)); 363 ``` 364 365 366## storageStatistics.getFreeSize<sup>9+</sup> 367 368getFreeSize(callback: AsyncCallback<number>): void 369 370Obtains the available space of the built-in memory card. This API uses a callback to return the result. 371 372**Required permissions**: ohos.permission.STORAGE_MANAGER 373 374**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 375 376 377This is a system API and cannot be called by third-party applications. 378 379 380**Parameters** 381 382 | Name | Type | Mandatory| Description | 383 | -------- | ------------------------------------ | ---- | ------------------------- | 384 | callback | callback:AsyncCallback<number> | Yes | Callback invoked to return the available space of the built-in memory card.| 385 386**Example** 387 388 ```js 389 storageStatistics.getFreeSize(function(error, number){ 390 // Do something. 391 console.info("getFreeSize successfully:"+ JSON.stringify(number)); 392 }); 393 ``` 394 395## storageStatistics.getSystemSize<sup>9+</sup> 396 397getSystemSize(): Promise<number> 398 399Asynchronously obtains the system space. This API uses a promise to return the result. 400 401**Required permissions**: ohos.permission.STORAGE_MANAGER 402 403**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 404 405 406This is a system API and cannot be called by third-party applications. 407 408 409**Return value** 410 411 | Type | Description | 412 | --------------------- | ---------------- | 413 | Promise<number> | Promise used to return the system space obtained.| 414 415**Example** 416 417 ```js 418 storageStatistics.getSystemSize().then(function(number){ 419 console.info("getSystemSize successfully:"+ number); 420 }).catch(function(err){ 421 console.info("getSystemSize failed with error:"+ err); 422 }); 423 ``` 424 425## storageStatistics.getSystemSize<sup>9+</sup> 426 427getSystemSize(callback:AsyncCallback<number>):void 428 429Asynchronously obtains the system space. This API uses a callback to return the result. 430 431**Required permissions**: ohos.permission.STORAGE_MANAGER 432 433**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 434 435 436This is a system API and cannot be called by third-party applications. 437 438 439**Parameters** 440 441 | Name | Type | Mandatory| Description | 442 | ---------- | ------------------------------------ | ---- | -------------------------- | 443 | callback | callback:AsyncCallback<number> | Yes | Callback used to return the system space obtained.| 444 445**Example** 446 447 ```js 448 storageStatistics.getSystemSize(function(error, number){ 449 // Do something. 450 console.info("getSystemSize successfully:"+ number); 451 }); 452 ``` 453 454## storageStatistics.getUserStorageStats<sup>9+</sup> 455 456getUserStorageStats(userId? : number): Promise<StorageStats> 457 458Asynchronously obtains the space occupied by each type of user data. This API uses a promise to return the result. 459 460**Required permissions**: ohos.permission.STORAGE_MANAGER 461 462**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 463 464 465This is a system API and cannot be called by third-party applications. 466 467 468**Parameters** 469 470 | Name | Type | Mandatory| Description| 471 | ---------- | ------ | ---- | ---- | 472 | userId | number | No | User ID.<br>Value:<br>- Set this parameter to the ID of the user to be queried.<br>- If no value is specified, information about the current user is queried.| 473 474**Return value** 475 476 | Type | Description | 477 | --------------------- | ---------------- | 478 | Promise<[StorageStats](#StorageStats)> | Promise used to return the information obtained.| 479 480**Example** 481 482 ```js 483 let userId = 1; 484 storageStatistics.getUserStorageStats(userId).then(function(StorageStats){ 485 console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); 486 }).catch(function(err){ 487 console.info("getUserStorageStats failed with error:"+ err); 488 }); 489 ``` 490 491## storageStatistics.getUserStorageStats<sup>9+</sup> 492 493getUserStorageStats(userId: number, callback:AsyncCallback<StorageStats>):void 494 495Asynchronously obtains the space occupied by each type of user data. This API uses a callback to return the result. 496 497**Required permissions**: ohos.permission.STORAGE_MANAGER 498 499**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 500 501 502This is a system API and cannot be called by third-party applications. 503 504 505**Parameters** 506 507 | Name | Type | Mandatory| Description | 508 | ---------- | ------------------------------------ | ---- | -------------------------- | 509 | userId | number | No | User ID.<br>Value:<br>- Set this parameter to the ID of the user to be queried.<br>- If no value is specified, information about the current user is queried. | 510 | callback | callback:AsyncCallback<[StorageStats](#StorageStats)> | Yes | Callback invoked to return the information obtained.| 511 512**Example** 513 514 ```js 515 let userId = 1; 516 storageStatistics.getUserStorageStats(userId, function(error, StorageStats){ 517 // Do something. 518 console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats)); 519 }); 520 ``` 521 522 523## StorageStats<sup>9+</sup> 524 525### Attributes 526 527**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics 528 529 530This is a system API and cannot be called by third-party applications. 531 532| Name | Type | Description | 533| --------- | ------ | -------------- | 534| total | number | Total space of the built-in memory card. | 535| audio | number | Space occupied by audio data. | 536| video | number | Space occupied by video data.| 537| image | number | Space occupied by image data. | 538| file | number | Space occupied by files. | 539| app | number | Space occupied by application data.| 540