js-apis-file-storage-statistics.md 25.5 KB
Newer Older
A
Annie_wang 已提交
1
# @ohos.file.storageStatistics (Application Storage Statistics)
A
annie_wangli 已提交
2

A
Annie_wang 已提交
3 4
The **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.

S
shawn_he 已提交
5
> **NOTE**
A
annie_wangli 已提交
6
>
A
Annie_wang 已提交
7 8
> 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.

A
annie_wangli 已提交
9 10 11
## Modules to Import

```js
A
Annie_wang 已提交
12
import storageStatistics from "@ohos.file.storageStatistics";
A
annie_wangli 已提交
13 14
```

A
Annie_wang 已提交
15
## storageStatistics.getTotalSizeOfVolume
A
annie_wangli 已提交
16 17 18

getTotalSizeOfVolume(volumeUuid: string): Promise<number>

A
Annie_wang 已提交
19
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
A
Annie_wang 已提交
20 21

**Required permissions**: ohos.permission.STORAGE_MANAGER
A
annie_wangli 已提交
22

A
annie_wangli 已提交
23 24
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
25
**System API**: This is a system API.
A
Annie_wang 已提交
26 27

**Parameters**
A
annie_wangli 已提交
28

A
Annie_wang 已提交
29 30 31
  | Name    | Type  | Mandatory| Description|
  | ---------- | ------ | ---- | ---- |
  | volumeUuid | string | Yes  | UUID of the volume.|
A
annie_wangli 已提交
32

A
Annie_wang 已提交
33
**Return value**
A
annie_wangli 已提交
34

A
Annie_wang 已提交
35 36
  | Type                 | Description            |
  | --------------------- | ---------------- |
A
Annie_wang 已提交
37
  | Promise<number> | Promise used to return the total volume size obtained.|
A
annie_wangli 已提交
38

A
Annie_wang 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
52
**Example**
A
annie_wangli 已提交
53 54 55

  ```js
  let uuid = "";
A
Annie_wang 已提交
56
  storageStatistics.getTotalSizeOfVolume(uuid).then(function(number){
A
annie_wangli 已提交
57 58 59 60 61 62
      console.info("getTotalSizeOfVolume successfully:"+ number);
  }).catch(function(err){
      console.info("getTotalSizeOfVolume failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
63
## storageStatistics.getTotalSizeOfVolume
A
annie_wangli 已提交
64

A
Annie_wang 已提交
65
getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void
A
annie_wangli 已提交
66

A
Annie_wang 已提交
67
Obtains the total size (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
68 69

**Required permissions**: ohos.permission.STORAGE_MANAGER
A
annie_wangli 已提交
70

A
annie_wangli 已提交
71 72
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
73
**System API**: This is a system API.
A
Annie_wang 已提交
74 75

**Parameters**
A
annie_wangli 已提交
76

A
Annie_wang 已提交
77 78 79
  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
  | volumeUuid | string                               | Yes  | UUID of the volume.                      |
A
Annie_wang 已提交
80
  | callback   | AsyncCallback<number>          | Yes  | Callback invoked to return the total volume size obtained.|
A
annie_wangli 已提交
81

A
Annie_wang 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
95
**Example**
A
annie_wangli 已提交
96 97 98

  ```js
  let uuid = "";
A
Annie_wang 已提交
99
  storageStatistics.getTotalSizeOfVolume(uuid, function(error, number){
A
Annie_wang 已提交
100
      // Do something.
A
annie_wangli 已提交
101
      console.info("getTotalSizeOfVolume successfully:"+ number);
A
annie_wangli 已提交
102 103 104
  });
  ```

A
Annie_wang 已提交
105
## storageStatistics.getFreeSizeOfVolume
A
annie_wangli 已提交
106 107 108

getFreeSizeOfVolume(volumeUuid: string): Promise<number>

A
Annie_wang 已提交
109
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses a promise to return the result.
A
annie_wangli 已提交
110

A
Annie_wang 已提交
111 112
**Required permissions**: ohos.permission.STORAGE_MANAGER

A
annie_wangli 已提交
113 114
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
115
**System API**: This is a system API.
A
Annie_wang 已提交
116 117

**Parameters**
A
annie_wangli 已提交
118

A
Annie_wang 已提交
119 120 121
  | Name    | Type  | Mandatory| Description|
  | ---------- | ------ | ---- | ---- |
  | volumeUuid | string | Yes  | UUID of the volume.|
A
annie_wangli 已提交
122

A
Annie_wang 已提交
123
**Return value**
A
annie_wangli 已提交
124

A
Annie_wang 已提交
125 126
  | Type                 | Description              |
  | --------------------- | ------------------ |
A
Annie_wang 已提交
127
  | Promise<number> | Promise used to return the available volume space obtained.|
A
annie_wangli 已提交
128

A
Annie_wang 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
142
**Example**
A
annie_wangli 已提交
143 144 145

  ```js
  let uuid = "";
A
Annie_wang 已提交
146
  storageStatistics.getFreeSizeOfVolume(uuid).then(function(number){
A
annie_wangli 已提交
147 148 149 150 151 152 153
      console.info("getFreeSizeOfVolume successfully:"+ number);
  }).catch(function(err){
      console.info("getFreeSizeOfVolume failed with error:"+ err);
  });
  
  ```

A
Annie_wang 已提交
154
## storageStatistics.getFreeSizeOfVolume
A
annie_wangli 已提交
155

A
Annie_wang 已提交
156
getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void
A
annie_wangli 已提交
157

A
Annie_wang 已提交
158
Obtains the available space (in bytes) of the specified volume in an external storage device. This API uses an asynchronous callback to return the result.
A
annie_wangli 已提交
159

A
Annie_wang 已提交
160 161
**Required permissions**: ohos.permission.STORAGE_MANAGER

A
annie_wangli 已提交
162 163
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
164
**System API**: This is a system API.
A
Annie_wang 已提交
165 166

**Parameters**
A
annie_wangli 已提交
167

A
Annie_wang 已提交
168 169 170
  | Name    | Type                                | Mandatory| Description                        |
  | ---------- | ------------------------------------ | ---- | ---------------------------- |
  | volumeUuid | string                               | Yes  | UUID of the volume.                        |
A
Annie_wang 已提交
171
  | callback   | AsyncCallback<number>          | Yes  | Callback invoked to return the available volume space obtained.|
A
annie_wangli 已提交
172

A
Annie_wang 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
186
**Example**
A
annie_wangli 已提交
187 188 189

  ```js
  let uuid = "";
A
Annie_wang 已提交
190
  storageStatistics.getFreeSizeOfVolume(uuid, function(error, number){
A
Annie_wang 已提交
191
      // Do something.
A
annie_wangli 已提交
192
      console.info("getFreeSizeOfVolume successfully:"+ number);
A
annie_wangli 已提交
193 194 195
  });
  ```

A
Annie_wang 已提交
196
## storageStatistics.getBundleStats<sup>9+</sup>
A
annie_wangli 已提交
197

A
annie_wangli 已提交
198
getBundleStats(packageName: string): Promise&lt;BundleStats&gt;
A
annie_wangli 已提交
199

A
Annie_wang 已提交
200
Obtains the space (in bytes) of an application. This API uses a promise to return the result.
A
Annie_wang 已提交
201 202

**Required permissions**: ohos.permission.STORAGE_MANAGER
A
annie_wangli 已提交
203 204

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
A
annie_wangli 已提交
205

A
Annie_wang 已提交
206
**System API**: This is a system API.
A
Annie_wang 已提交
207 208

**Parameters**
A
annie_wangli 已提交
209

A
Annie_wang 已提交
210 211 212
  | Name     | Type  | Mandatory| Description    |
  | ----------- | ------ | ---- | -------- |
  | packageName | string | Yes  | Bundle name of the application.|
A
Annie_wang 已提交
213 214

**Return value**
A
annie_wangli 已提交
215

A
Annie_wang 已提交
216 217
  | Type                                      | Description                      |
  | ------------------------------------------ | -------------------------- |
A
Annie_wang 已提交
218
  | Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application space obtained.|
A
annie_wangli 已提交
219

A
Annie_wang 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
233
**Example**
A
annie_wangli 已提交
234 235 236

  ```js
  let packageName = "";
A
Annie_wang 已提交
237
  storageStatistics.getBundleStats(packageName).then(function(BundleStats){
A
annie_wangli 已提交
238 239 240 241 242 243
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
  }).catch(function(err){
      console.info("getBundleStats failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
244
## storageStatistics.getBundleStats<sup>9+</sup>
A
annie_wangli 已提交
245

A
annie_wangli 已提交
246
getBundleStats(packageName: string,  callback: AsyncCallback&lt;BundleStats&gt;): void
A
annie_wangli 已提交
247

A
Annie_wang 已提交
248
Obtains the space (in bytes) of an application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
249 250

**Required permissions**: ohos.permission.STORAGE_MANAGER
A
annie_wangli 已提交
251

A
annie_wangli 已提交
252
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
A
annie_wangli 已提交
253

A
Annie_wang 已提交
254
**System API**: This is a system API.
A
Annie_wang 已提交
255 256

**Parameters**
A
annie_wangli 已提交
257

A
Annie_wang 已提交
258 259 260
  | Name  | Type                                                     | Mandatory| Description                                |
  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
  | packageName | string | Yes  | Bundle name of the application.|
A
Annie_wang 已提交
261
  | callback | AsyncCallback&lt;[Bundlestats](#bundlestats9)&gt; | Yes  | Callback invoked to return the application space obtained.|
A
Annie_wang 已提交
262

A
Annie_wang 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600008 | No such object. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
276
**Example**
A
annie_wangli 已提交
277 278 279

  ```js
  let packageName = "";
A
Annie_wang 已提交
280
  storageStatistics.getBundleStats(packageName, function(error, BundleStats){
A
Annie_wang 已提交
281
      // Do something.
A
annie_wangli 已提交
282
      console.info("getBundleStats successfully:"+ JSON.stringify(BundleStats));
A
annie_wangli 已提交
283 284 285
  });
  ```

A
Annie_wang 已提交
286
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
A
Annie_wang 已提交
287

A
Annie_wang 已提交
288
getCurrentBundleStats(): Promise&lt;BundleStats&gt;
A
Annie_wang 已提交
289

A
Annie_wang 已提交
290
Obtains the space (in bytes) of this third-party application. This API uses a promise to return the result.
A
Annie_wang 已提交
291 292 293

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
294
**Return value**
A
Annie_wang 已提交
295

A
Annie_wang 已提交
296 297
  | Type                                       | Description                      |
  | ------------------------------------------ | -------------------------- |
A
Annie_wang 已提交
298
  | Promise&lt;[Bundlestats](#bundlestats9)&gt; | Promise used to return the application storage space obtained.     |
A
Annie_wang 已提交
299

A
Annie_wang 已提交
300 301 302 303 304 305 306 307 308 309
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
310
**Example**
A
Annie_wang 已提交
311 312

  ```js
A
Annie_wang 已提交
313 314
  let bundleStats = storageStatistics.getCurrentBundleStats();
  console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
A
Annie_wang 已提交
315 316
  ```

A
Annie_wang 已提交
317
## storageStatistics.getCurrentBundleStats<sup>9+</sup>
A
Annie_wang 已提交
318

A
Annie_wang 已提交
319
getCurrentBundleStats(callback: AsyncCallback&lt;BundleStats&gt;): void
A
Annie_wang 已提交
320

A
Annie_wang 已提交
321
Obtains the space (in bytes) of this third-party application. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
322

A
Annie_wang 已提交
323 324
**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
325
**Parameters**
A
Annie_wang 已提交
326

A
Annie_wang 已提交
327 328
  | Name   | Type                                                      | Mandatory | Description                                |
  | -------- | --------------------------------------------------------- | ---- | ------------------------------------ |
A
Annie_wang 已提交
329
  | callback | AsyncCallback&lt;[BundleStats](#bundlestats9)&gt;          | Yes  | Callback invoked to return the application space obtained.       |
A
Annie_wang 已提交
330

A
Annie_wang 已提交
331 332 333 334 335 336 337 338 339 340
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
341
**Example**
A
Annie_wang 已提交
342 343

  ```js
A
Annie_wang 已提交
344
  storageStatistics.getCurrentBundleStats(function(error, bundleStats){
A
Annie_wang 已提交
345 346 347 348
      // Do something.
      console.info("getCurrentBundleStats successfully:"+ JSON.stringify(bundleStats));
  });
  ```
A
Annie_wang 已提交
349

A
annie_wangli 已提交
350 351 352
## BundleStats<sup>9+</sup>

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics
A
annie_wangli 已提交
353

A
Annie_wang 已提交
354 355
| Name     | Type  | Readable| Writable| Description          |
| --------- | ------ | --- | ---- | -------------- |
A
Annie_wang 已提交
356 357 358
| appSize   | number | Yes| No| Size of the application, in bytes.   |
| cacheSize | number | Yes| No| Cache size of the application, in bytes.  |
| dataSize  | number | Yes| No| Total data size of the application, in bytes.|
A
Annie_wang 已提交
359

A
Annie_wang 已提交
360
## storageStatistics.getTotalSize<sup>9+</sup>
A
Annie_wang 已提交
361

A
Annie_wang 已提交
362
getTotalSize(): Promise&lt;number&gt;
A
Annie_wang 已提交
363

A
Annie_wang 已提交
364
Obtains the total size (in bytes) of the built-in storage. This API uses a promise to return the result.
A
Annie_wang 已提交
365 366 367 368 369

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
370
**System API**: This is a system API.
A
Annie_wang 已提交
371 372

**Return value**
A
Annie_wang 已提交
373

A
Annie_wang 已提交
374 375
  | Type                  | Description              |
  | --------------------- | ------------------ |
A
Annie_wang 已提交
376
  | Promise&lt;number&gt; | Promise used to return the total built-in storage size obtained.  |
A
Annie_wang 已提交
377

A
Annie_wang 已提交
378 379 380 381 382 383 384 385 386 387 388 389
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
390
**Example**
A
Annie_wang 已提交
391 392

  ```js
A
Annie_wang 已提交
393 394
  let number = storageStatistics.getTotalSize();
  console.info("getTotalSize successfully:"+ JSON.stringify(number));
A
Annie_wang 已提交
395 396
  ```

A
Annie_wang 已提交
397 398 399
## storageStatistics.getTotalSize<sup>9+</sup>

getTotalSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
400

A
Annie_wang 已提交
401
Obtains the total size (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
402 403 404 405 406

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
407
**System API**: This is a system API.
A
Annie_wang 已提交
408 409

**Parameters**
A
Annie_wang 已提交
410

A
Annie_wang 已提交
411 412
  | Name   | Type                                 | Mandatory | Description                    |
  | -------- | ------------------------------------ | ---- | ------------------------ |
A
Annie_wang 已提交
413
  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the built-in storage size obtained.|
A
Annie_wang 已提交
414

A
Annie_wang 已提交
415 416 417 418 419 420 421 422 423 424 425 426
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
427
**Example**
A
Annie_wang 已提交
428 429

  ```js
A
Annie_wang 已提交
430
  storageStatistics.getTotalSize(function(error, number){
A
Annie_wang 已提交
431 432 433 434 435
      // Do something.
      console.info("getTotalSize successfully:"+ JSON.stringify(number));
  });
  ```

A
Annie_wang 已提交
436
## storageStatistics.getFreeSize<sup>9+</sup>
A
Annie_wang 已提交
437

A
Annie_wang 已提交
438
getFreeSize(): Promise&lt;number&gt;
A
Annie_wang 已提交
439

A
Annie_wang 已提交
440
Obtains the available space (in bytes) of the built-in storage. This API uses a promise to return the result.
A
Annie_wang 已提交
441 442 443 444 445

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
446
**System API**: This is a system API.
A
Annie_wang 已提交
447 448

**Return value**
A
Annie_wang 已提交
449

A
Annie_wang 已提交
450 451
  | Type                  | Description              |
  | --------------------- | ------------------ |
A
Annie_wang 已提交
452
  | Promise&lt;number&gt; | Promise used to return the available space of the built-in storage obtained.|
A
Annie_wang 已提交
453

A
Annie_wang 已提交
454 455 456 457 458 459 460 461 462 463 464 465
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
466
**Example**
A
Annie_wang 已提交
467 468

  ```js
A
Annie_wang 已提交
469 470
  let number = storageStatistics.getFreeSize();
  console.info("getFreeSize successfully:"+ JSON.stringify(number));
A
Annie_wang 已提交
471 472
  ```

A
Annie_wang 已提交
473
## storageStatistics.getFreeSize<sup>9+</sup>
A
Annie_wang 已提交
474

A
Annie_wang 已提交
475
getFreeSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
476

A
Annie_wang 已提交
477
Obtains the available space (in bytes) of the built-in storage. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
478 479 480 481 482

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
483
**System API**: This is a system API.
A
Annie_wang 已提交
484 485

**Parameters**
A
Annie_wang 已提交
486

A
Annie_wang 已提交
487 488
  | Name   | Type                                 | Mandatory| Description                      |
  | -------- | ------------------------------------ | ---- | ------------------------- |
A
Annie_wang 已提交
489
  | callback | AsyncCallback&lt;number&gt;          | Yes  | Callback invoked to return the available space of the built-in storage obtained.|
A
Annie_wang 已提交
490

A
Annie_wang 已提交
491 492 493 494 495 496 497 498 499 500 501 502
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
503
**Example**
A
Annie_wang 已提交
504 505

  ```js
A
Annie_wang 已提交
506
  storageStatistics.getFreeSize(function(error, number){
A
Annie_wang 已提交
507 508 509 510 511
      // Do something.
      console.info("getFreeSize successfully:"+ JSON.stringify(number));
  });
  ```

A
Annie_wang 已提交
512
## storageStatistics.getSystemSize<sup>9+</sup>
A
Annie_wang 已提交
513 514 515

getSystemSize(): Promise&lt;number&gt;

A
Annie_wang 已提交
516
Obtains the system data space, in bytes. This API uses a promise to return the result.
A
Annie_wang 已提交
517 518 519 520 521

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
522
**System API**: This is a system API.
A
Annie_wang 已提交
523 524

**Return value**
A
Annie_wang 已提交
525

A
Annie_wang 已提交
526 527
  | Type                 | Description            |
  | --------------------- | ---------------- |
A
Annie_wang 已提交
528
  | Promise&lt;number&gt; | Promise used to return the system data space obtained.|
A
Annie_wang 已提交
529

A
Annie_wang 已提交
530 531 532 533 534 535 536 537 538 539 540 541
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
542
**Example**
A
Annie_wang 已提交
543 544

  ```js
A
Annie_wang 已提交
545
  storageStatistics.getSystemSize().then(function(number){
A
Annie_wang 已提交
546 547 548 549 550 551
      console.info("getSystemSize successfully:"+ number);
  }).catch(function(err){
      console.info("getSystemSize failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
552
## storageStatistics.getSystemSize<sup>9+</sup>
A
Annie_wang 已提交
553

A
Annie_wang 已提交
554
getSystemSize(callback: AsyncCallback&lt;number&gt;): void
A
Annie_wang 已提交
555

A
Annie_wang 已提交
556
Obtains the system data space, in bytes. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
557 558 559 560 561

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
562
**System API**: This is a system API.
A
Annie_wang 已提交
563 564

**Parameters**
A
Annie_wang 已提交
565

A
Annie_wang 已提交
566 567
  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
A
Annie_wang 已提交
568
  | callback   |  AsyncCallback&lt;number&gt;         | Yes  | Callback invoked to return the system data space obtained.|
A
Annie_wang 已提交
569

A
Annie_wang 已提交
570 571 572 573 574 575 576 577 578 579 580 581
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
582
**Example**
A
Annie_wang 已提交
583 584

  ```js
A
Annie_wang 已提交
585
  storageStatistics.getSystemSize(function(error, number){
A
Annie_wang 已提交
586 587 588 589 590
      // Do something.
      console.info("getSystemSize successfully:"+ number);
  });
  ```

A
Annie_wang 已提交
591 592
## storageStatistics.getUserStorageStats<sup>9+</sup>

A
Annie_wang 已提交
593 594 595 596 597 598 599 600
getUserStorageStats(): Promise&lt;StorageStats&gt;

Obtains the storage statistics (in bytes) of this user. This API uses a promise to return the result.

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
601
**System API**: This is a system API.
A
Annie_wang 已提交
602 603 604 605 606

**Return value**

  | Type                 | Description            |
  | --------------------- | ---------------- |
A
Annie_wang 已提交
607
  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the storage information obtained.|
A
Annie_wang 已提交
608

A
Annie_wang 已提交
609 610 611 612 613 614 615 616 617 618 619 620
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
**Example**

  ```js
  storageStatistics.getUserStorageStats().then(function(StorageStats){
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  }).catch(function(err){
      console.info("getUserStorageStats failed with error:"+ err);
  });
  ```

## storageStatistics.getUserStorageStats<sup>9+</sup>

getUserStorageStats(callback: AsyncCallback&lt;StorageStats&gt;): void

Obtains the storage statistics (in bytes) of this user. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
641
**System API**: This is a system API.
A
Annie_wang 已提交
642 643 644 645 646 647 648

**Parameters**

  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback invoked to return the information obtained.|

A
Annie_wang 已提交
649 650 651 652 653 654 655 656 657 658 659 660
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
661 662 663 664 665 666 667 668
**Example**

  ```js
  storageStatistics.getUserStorageStats(function(error, StorageStats){
      // Do something.
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  });
  ```
A
Annie_wang 已提交
669 670 671

## storageStatistics.getUserStorageStats<sup>9+</sup>

A
Annie_wang 已提交
672
getUserStorageStats(userId: number): Promise&lt;StorageStats&gt;
A
Annie_wang 已提交
673

A
Annie_wang 已提交
674
Obtains the storage statistics (in bytes) of the specified user. This API uses a promise to return the result.
A
Annie_wang 已提交
675 676 677 678 679

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
680
**System API**: This is a system API.
A
Annie_wang 已提交
681 682

**Parameters**
A
Annie_wang 已提交
683

A
Annie_wang 已提交
684 685
  | Name    | Type  | Mandatory| Description|
  | ---------- | ------ | ---- | ---- |
A
Annie_wang 已提交
686
  | userId | number | Yes  | User ID|
A
Annie_wang 已提交
687

A
Annie_wang 已提交
688
**Return value**
A
Annie_wang 已提交
689

A
Annie_wang 已提交
690 691
  | Type                 | Description            |
  | --------------------- | ---------------- |
A
Annie_wang 已提交
692
  | Promise&lt;[StorageStats](#storagestats9)&gt; | Promise used to return the storage information obtained.|
A
Annie_wang 已提交
693

A
Annie_wang 已提交
694 695 696 697 698 699 700 701 702 703 704 705 706
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600009 | User if out of range. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
707
**Example**
A
Annie_wang 已提交
708 709

  ```js
A
Annie_wang 已提交
710
  let userId = 100;
A
Annie_wang 已提交
711
  storageStatistics.getUserStorageStats(userId).then(function(StorageStats){
A
Annie_wang 已提交
712 713 714 715 716 717
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  }).catch(function(err){
      console.info("getUserStorageStats failed with error:"+ err);
  });
  ```

A
Annie_wang 已提交
718
## storageStatistics.getUserStorageStats<sup>9+</sup>
A
Annie_wang 已提交
719

A
Annie_wang 已提交
720
getUserStorageStats(userId: number, callback: AsyncCallback&lt;StorageStats&gt;): void
A
Annie_wang 已提交
721

A
Annie_wang 已提交
722
Obtains the storage statistics (in bytes) of the specified user. This API uses an asynchronous callback to return the result.
A
Annie_wang 已提交
723 724 725 726 727

**Required permissions**: ohos.permission.STORAGE_MANAGER

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
728
**System API**: This is a system API.
A
Annie_wang 已提交
729 730

**Parameters**
A
Annie_wang 已提交
731

A
Annie_wang 已提交
732 733
  | Name    | Type                                | Mandatory| Description                      |
  | ---------- | ------------------------------------ | ---- | -------------------------- |
A
Annie_wang 已提交
734
  | userId | number                               | Yes  | User ID.|
A
Annie_wang 已提交
735
  | callback   | AsyncCallback&lt;[StorageStats](#storagestats9)&gt; | Yes  | Callback invoked to return the information obtained.|
A
Annie_wang 已提交
736

A
Annie_wang 已提交
737 738 739 740 741 742 743 744 745 746 747 748 749
**Error codes**

For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).

| ID| Error Message|
| -------- | -------- |
| 201 | Permission verification failed. |
| 202 | The caller is not a system application. |
| 401 | The input parameter is invalid. |
| 13600001 | IPC error. |
| 13600009 | User if out of range. |
| 13900032 | Unknown error. |

A
Annie_wang 已提交
750
**Example**
A
Annie_wang 已提交
751 752

  ```js
A
Annie_wang 已提交
753
  let userId = 100;
A
Annie_wang 已提交
754
  storageStatistics.getUserStorageStats(userId, function(error, StorageStats){
A
Annie_wang 已提交
755 756 757 758 759 760 761 762 763
      // Do something.
      console.info("getUserStorageStats successfully:"+ JSON.stringify(StorageStats));
  });
  ```

## StorageStats<sup>9+</sup>

**System capability**: SystemCapability.FileManagement.StorageService.SpatialStatistics

A
Annie_wang 已提交
764
**System API**: This is a system API.
A
Annie_wang 已提交
765

A
Annie_wang 已提交
766 767
| Name     | Type  | Readable | Writable | Description          |
| --------- | ------ | ---- | ----- | -------------- |
A
Annie_wang 已提交
768 769 770 771 772 773
| total   | number | Yes| No| Total size of the built-in storage, in bytes.   |
| audio | number  |Yes| No| Space occupied by audio data, in bytes. |
| video  | number | Yes| No| Space occupied by video data, in bytes.|
| image   | number | Yes| No| Space occupied by image data, in bytes.  |
| file | number | Yes| No| Space occupied by files, in bytes. |
| app  | number | Yes| No| Space occupied by application data, in bytes.|