1/* 2 * Copyright (C) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit CoreFileKit 19 */ 20 21import { AsyncCallback, Callback } from './@ohos.base'; 22 23/** 24 * Provides filesystem statistics APIs. 25 * 26 * @namespace storageStatistics 27 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 28 * @since 8 29 */ 30declare namespace storageStatistics { 31 /** 32 * Get the total size of volume. 33 * 34 * @permission ohos.permission.STORAGE_MANAGER 35 * @param { string } volumeUuid - The uuid of the volume 36 * @param { AsyncCallback<number> } callback - callback 37 * @throws { BusinessError } 201 - Permission verification failed. 38 * @throws { BusinessError } 202 - The caller is not a system application. 39 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 40parameters are left unspecified; 41 * <br>2.Incorrect parameter types. 42 * @throws { BusinessError } 13600001 - IPC error. 43 * @throws { BusinessError } 13600008 - No such object. 44 * @throws { BusinessError } 13900042 - Unknown error. 45 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 46 * @systemapi 47 * @since 8 48 */ 49 function getTotalSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void; 50 51 /** 52 * Get the total size of volume. 53 * 54 * @permission ohos.permission.STORAGE_MANAGER 55 * @param { string } volumeUuid - The uuid of the volume 56 * @returns { Promise<number> } return Promise 57 * @throws { BusinessError } 201 - Permission verification failed. 58 * @throws { BusinessError } 202 - The caller is not a system application. 59 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 60parameters are left unspecified; 61 * <br>2.Incorrect parameter types. 62 * @throws { BusinessError } 13600001 - IPC error. 63 * @throws { BusinessError } 13600008 - No such object. 64 * @throws { BusinessError } 13900042 - Unknown error. 65 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 66 * @systemapi 67 * @since 8 68 */ 69 function getTotalSizeOfVolume(volumeUuid: string): Promise<number>; 70 /** 71 * Get the free size of volume. 72 * 73 * @permission ohos.permission.STORAGE_MANAGER 74 * @param { string } volumeUuid - The uuid of the volume 75 * @param { AsyncCallback<number> } callback - callback 76 * @throws { BusinessError } 201 - Permission verification failed. 77 * @throws { BusinessError } 202 - The caller is not a system application. 78 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 79parameters are left unspecified; 80 * <br>2.Incorrect parameter types. 81 * @throws { BusinessError } 13600001 - IPC error. 82 * @throws { BusinessError } 13600008 - No such object. 83 * @throws { BusinessError } 13900042 - Unknown error. 84 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 85 * @systemapi 86 * @since 8 87 */ 88 function getFreeSizeOfVolume(volumeUuid: string, callback: AsyncCallback<number>): void; 89 90 /** 91 * Get the free size of volume. 92 * 93 * @permission ohos.permission.STORAGE_MANAGER 94 * @param { string } volumeUuid - The uuid of the volume 95 * @returns { Promise<number> } return Promise 96 * @throws { BusinessError } 201 - Permission verification failed. 97 * @throws { BusinessError } 202 - The caller is not a system application. 98 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 99parameters are left unspecified; 100 * <br>2.Incorrect parameter types. 101 * @throws { BusinessError } 13600001 - IPC error. 102 * @throws { BusinessError } 13600008 - No such object. 103 * @throws { BusinessError } 13900042 - Unknown error. 104 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 105 * @systemapi 106 * @since 8 107 */ 108 function getFreeSizeOfVolume(volumeUuid: string): Promise<number>; 109 110 /** 111 * Get the bundle statistics. 112 * 113 * @interface BundleStats 114 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 115 * @since 9 116 */ 117 export interface BundleStats { 118 /** 119 * The size of application installation data. 120 * 121 * @type { number } 122 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 123 * @since 9 124 */ 125 appSize: number; 126 127 /** 128 * The size of application cache data. 129 * 130 * @type { number } 131 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 132 * @since 9 133 */ 134 cacheSize: number; 135 136 /** 137 * The size of application local data, distributed data and database data. 138 * 139 * @type { number } 140 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 141 * @since 9 142 */ 143 dataSize: number; 144 } 145 /** 146 * Get the bundle statistics. 147 * 148 * @permission ohos.permission.STORAGE_MANAGER 149 * @param { string } packageName - The name of the application 150 * @param { AsyncCallback<BundleStats> } callback - callback 151 * @throws { BusinessError } 201 - Permission verification failed. 152 * @throws { BusinessError } 202 - The caller is not a system application. 153 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 154parameters are left unspecified; 155 * <br>2.Incorrect parameter types. 156 * @throws { BusinessError } 13600001 - IPC error. 157 * @throws { BusinessError } 13600008 - No such object. 158 * @throws { BusinessError } 13900042 - Unknown error. 159 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 160 * @systemapi 161 * @since 9 162 */ 163 /** 164 * Get the bundle statistics. 165 * 166 * @permission ohos.permission.STORAGE_MANAGER 167 * @param { string } packageName - The name of the application 168 * @param { AsyncCallback<BundleStats> } callback - callback 169 * @param { number } index - The index number of the clone application, the default value is 0. 170 * @throws { BusinessError } 201 - Permission verification failed. 171 * @throws { BusinessError } 202 - The caller is not a system application. 172 * @throws { BusinessError } 401 - The input parameter is invalid. 173 * @throws { BusinessError } 13600001 - IPC error. 174 * @throws { BusinessError } 13600008 - No such object. 175 * @throws { BusinessError } 13900042 - Unknown error. 176 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 177 * @systemapi 178 * @since 12 179 */ 180 function getBundleStats(packageName: string, callback: AsyncCallback<BundleStats>, index?: number): void; 181 182 /** 183 * Get the bundle statistics. 184 * 185 * @permission ohos.permission.STORAGE_MANAGER 186 * @param { string } packageName - The name of the application 187 * @returns { Promise<BundleStats> } return Promise 188 * @throws { BusinessError } 201 - Permission verification failed. 189 * @throws { BusinessError } 202 - The caller is not a system application. 190 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 191parameters are left unspecified; 192 * <br>2.Incorrect parameter types. 193 * @throws { BusinessError } 13600001 - IPC error. 194 * @throws { BusinessError } 13600008 - No such object. 195 * @throws { BusinessError } 13900042 - Unknown error. 196 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 197 * @systemapi 198 * @since 9 199 */ 200 /** 201 * Get the bundle statistics. 202 * 203 * @permission ohos.permission.STORAGE_MANAGER 204 * @param { string } packageName - The name of the application 205 * @param { number } index - The index number of the clone application, the default value is 0. 206 * @returns { Promise<BundleStats> } return Promise 207 * @throws { BusinessError } 201 - Permission verification failed. 208 * @throws { BusinessError } 202 - The caller is not a system application. 209 * @throws { BusinessError } 401 - The input parameter is invalid. 210 * @throws { BusinessError } 13600001 - IPC error. 211 * @throws { BusinessError } 13600008 - No such object. 212 * @throws { BusinessError } 13900042 - Unknown error. 213 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 214 * @systemapi 215 * @since 12 216 */ 217 function getBundleStats(packageName: string, index?: number): Promise<BundleStats>; 218 219 /** 220 * Get the current bundle statistics. 221 * 222 * @param { AsyncCallback<BundleStats> } callback - callback 223 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 224parameters are left unspecified; 225 * @throws { BusinessError } 13600001 - IPC error. 226 * @throws { BusinessError } 13900042 - Unknown error. 227 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 228 * @since 9 229 */ 230 function getCurrentBundleStats(callback: AsyncCallback<BundleStats>): void; 231 232 /** 233 * Get the current bundle statistics. 234 * 235 * @returns { Promise<BundleStats> } return Promise 236 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 237parameters are left unspecified; 238 * @throws { BusinessError } 13600001 - IPC error. 239 * @throws { BusinessError } 13900042 - Unknown error. 240 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 241 * @since 9 242 */ 243 function getCurrentBundleStats(): Promise<BundleStats>; 244 245 /** 246 * Get the system size. 247 * 248 * @permission ohos.permission.STORAGE_MANAGER 249 * @param { AsyncCallback<number> } callback - callback 250 * @throws { BusinessError } 201 - Permission verification failed. 251 * @throws { BusinessError } 202 - The caller is not a system application. 252 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 253parameters are left unspecified; 254 * @throws { BusinessError } 13600001 - IPC error. 255 * @throws { BusinessError } 13900042 - Unknown error. 256 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 257 * @systemapi 258 * @since 9 259 */ 260 function getSystemSize(callback: AsyncCallback<number>): void; 261 262 /** 263 * Get the system size. 264 * 265 * @permission ohos.permission.STORAGE_MANAGER 266 * @returns { Promise<number> } return Promise 267 * @throws { BusinessError } 201 - Permission verification failed. 268 * @throws { BusinessError } 202 - The caller is not a system application. 269 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 270parameters are left unspecified; 271 * @throws { BusinessError } 13600001 - IPC error. 272 * @throws { BusinessError } 13900042 - Unknown error. 273 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 274 * @systemapi 275 * @since 9 276 */ 277 function getSystemSize(): Promise<number>; 278 279 /** 280 * Get the user storage statistics. 281 * 282 * @interface StorageStats 283 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 284 * @systemapi 285 * @since 9 286 */ 287 export interface StorageStats { 288 /** 289 * The total size of device. 290 * 291 * @type { number } 292 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 293 * @systemapi 294 * @since 9 295 */ 296 total: number; 297 298 /** 299 * The size of audio file. 300 * 301 * @type { number } 302 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 303 * @systemapi 304 * @since 9 305 */ 306 audio: number; 307 308 /** 309 * The size of video file. 310 * 311 * @type { number } 312 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 313 * @systemapi 314 * @since 9 315 */ 316 video: number; 317 318 /** 319 * The size of image file. 320 * 321 * @type { number } 322 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 323 * @systemapi 324 * @since 9 325 */ 326 image: number; 327 328 /** 329 * The size of other file. 330 * 331 * @type { number } 332 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 333 * @systemapi 334 * @since 9 335 */ 336 file: number; 337 338 /** 339 * The size of application. 340 * 341 * @type { number } 342 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 343 * @systemapi 344 * @since 9 345 */ 346 app: number; 347 } 348 349 /** 350 * Get the user storage statistics. 351 * 352 * @permission ohos.permission.STORAGE_MANAGER 353 * @returns { Promise<StorageStats> } return Promise 354 * @throws { BusinessError } 201 - Permission verification failed. 355 * @throws { BusinessError } 202 - The caller is not a system application. 356 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 357parameters are left unspecified; 358 * <br>2.Incorrect parameter types. 359 * @throws { BusinessError } 13600001 - IPC error. 360 * @throws { BusinessError } 13900042 - Unknown error. 361 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 362 * @systemapi 363 * @since 9 364 */ 365 function getUserStorageStats(): Promise<StorageStats>; 366 367 /** 368 * Get the user storage statistics. 369 * 370 * @permission ohos.permission.STORAGE_MANAGER 371 * @param { AsyncCallback<StorageStats> } callback - callback 372 * @throws { BusinessError } 201 - Permission verification failed. 373 * @throws { BusinessError } 202 - The caller is not a system application. 374 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 375parameters are left unspecified; 376 * <br>2.Incorrect parameter types. 377 * @throws { BusinessError } 13600001 - IPC error. 378 * @throws { BusinessError } 13900042 - Unknown error. 379 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 380 * @systemapi 381 * @since 9 382 */ 383 function getUserStorageStats(callback: AsyncCallback<StorageStats>): void; 384 385 /** 386 * Get the user storage statistics. 387 * 388 * @permission ohos.permission.STORAGE_MANAGER 389 * @param { number } userId - The id of the user 390 * @returns { Promise<StorageStats> } return Promise 391 * @throws { BusinessError } 201 - Permission verification failed. 392 * @throws { BusinessError } 202 - The caller is not a system application. 393 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 394parameters are left unspecified; 395 * <br>2.Incorrect parameter types. 396 * @throws { BusinessError } 13600001 - IPC error. 397 * @throws { BusinessError } 13600009 - User if out of range. 398 * @throws { BusinessError } 13900042 - Unknown error. 399 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 400 * @systemapi 401 * @since 9 402 */ 403 function getUserStorageStats(userId: number): Promise<StorageStats>; 404 405 /** 406 * Get the user storage statistics. 407 * 408 * @permission ohos.permission.STORAGE_MANAGER 409 * @param { number } userId - The id of the user 410 * @param { AsyncCallback<StorageStats> } callback - callback 411 * @throws { BusinessError } 201 - Permission verification failed. 412 * @throws { BusinessError } 202 - The caller is not a system application. 413 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory 414parameters are left unspecified; 415 * <br>2.Incorrect parameter types. 416 * @throws { BusinessError } 13600001 - IPC error. 417 * @throws { BusinessError } 13600009 - User if out of range. 418 * @throws { BusinessError } 13900042 - Unknown error. 419 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 420 * @systemapi 421 * @since 9 422 */ 423 function getUserStorageStats(userId: number, callback: AsyncCallback<StorageStats>): void; 424 425 /** 426 * Get the total size. 427 * 428 * @permission ohos.permission.STORAGE_MANAGER 429 * @param { AsyncCallback<number> } callback - callback 430 * @throws { BusinessError } 201 - Permission verification failed. 431 * @throws { BusinessError } 202 - The caller is not a system application. 432 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 433parameters are left unspecified; 434 * @throws { BusinessError } 13600001 - IPC error. 435 * @throws { BusinessError } 13900042 - Unknown error. 436 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 437 * @systemapi 438 * @since 9 439 */ 440 /** 441 * Get the total size. 442 * 443 * @param { AsyncCallback<number> } callback - callback 444 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 445parameters are left unspecified; 446 * @throws { BusinessError } 13600001 - IPC error. 447 * @throws { BusinessError } 13900042 - Unknown error. 448 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 449 * @since 15 450 */ 451 function getTotalSize(callback: AsyncCallback<number>): void; 452 453 /** 454 * Get the total size. 455 * 456 * @permission ohos.permission.STORAGE_MANAGER 457 * @returns { Promise<number> } return Promise 458 * @throws { BusinessError } 201 - Permission verification failed. 459 * @throws { BusinessError } 202 - The caller is not a system application. 460 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 461parameters are left unspecified; 462 * @throws { BusinessError } 13600001 - IPC error. 463 * @throws { BusinessError } 13900042 - Unknown error. 464 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 465 * @systemapi 466 * @since 9 467 */ 468 /** 469 * Get the total size. 470 * 471 * @returns { Promise<number> } return Promise 472 * @throws { BusinessError } 13600001 - IPC error. 473 * @throws { BusinessError } 13900042 - Unknown error. 474 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 475 * @since 15 476 */ 477 function getTotalSize(): Promise<number>; 478 479 /** 480 * Get the total size with sync interface 481 * 482 * @permission ohos.permission.STORAGE_MANAGER 483 * @returns { number } return the total size 484 * @throws { BusinessError } 201 - Permission verification failed. 485 * @throws { BusinessError } 202 - The caller is not a system application. 486 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 487parameters are left unspecified; 488 * @throws { BusinessError } 13600001 - IPC error. 489 * @throws { BusinessError } 13900042 - Unknown error. 490 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 491 * @systemapi 492 * @since 10 493 */ 494 /** 495 * Get the total size with sync interface 496 * 497 * @returns { number } return the total size 498 * @throws { BusinessError } 13600001 - IPC error. 499 * @throws { BusinessError } 13900042 - Unknown error. 500 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 501 * @since 15 502 */ 503 function getTotalSizeSync(): number; 504 505 /** 506 * Get the free size. 507 * 508 * @permission ohos.permission.STORAGE_MANAGER 509 * @param { AsyncCallback<number> } callback - callback 510 * @throws { BusinessError } 201 - Permission verification failed. 511 * @throws { BusinessError } 202 - The caller is not a system application. 512 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 513parameters are left unspecified; 514 * @throws { BusinessError } 13600001 - IPC error. 515 * @throws { BusinessError } 13900042 - Unknown error. 516 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 517 * @systemapi 518 * @since 9 519 */ 520 /** 521 * Get the free size. 522 * 523 * @param { AsyncCallback<number> } callback - callback 524 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 525parameters are left unspecified; 526 * @throws { BusinessError } 13600001 - IPC error. 527 * @throws { BusinessError } 13900042 - Unknown error. 528 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 529 * @since 15 530 */ 531 function getFreeSize(callback: AsyncCallback<number>): void; 532 533 /** 534 * Get the free size. 535 * 536 * @permission ohos.permission.STORAGE_MANAGER 537 * @returns { Promise<number> } return Promise 538 * @throws { BusinessError } 201 - Permission verification failed. 539 * @throws { BusinessError } 202 - The caller is not a system application. 540 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 541parameters are left unspecified; 542 * @throws { BusinessError } 13600001 - IPC error. 543 * @throws { BusinessError } 13900042 - Unknown error. 544 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 545 * @systemapi 546 * @since 9 547 */ 548 /** 549 * Get the free size. 550 * 551 * @returns { Promise<number> } return Promise 552 * @throws { BusinessError } 13600001 - IPC error. 553 * @throws { BusinessError } 13900042 - Unknown error. 554 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 555 * @since 15 556 */ 557 function getFreeSize(): Promise<number>; 558 559 /** 560 * Get the free size with sync interface. 561 * 562 * @permission ohos.permission.STORAGE_MANAGER 563 * @returns { number } return the free size 564 * @throws { BusinessError } 201 - Permission verification failed. 565 * @throws { BusinessError } 202 - The caller is not a system application. 566 * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Mandatory 567parameters are left unspecified; 568 * @throws { BusinessError } 13600001 - IPC error. 569 * @throws { BusinessError } 13900042 - Unknown error. 570 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 571 * @systemapi 572 * @since 10 573 */ 574 /** 575 * Get the free size with sync interface. 576 * 577 * @returns { number } return the free size 578 * @throws { BusinessError } 13600001 - IPC error. 579 * @throws { BusinessError } 13900042 - Unknown error. 580 * @syscap SystemCapability.FileManagement.StorageService.SpatialStatistics 581 * @since 15 582 */ 583 function getFreeSizeSync(): number; 584} 585 586export default storageStatistics; 587