1/* 2 * Copyright (c) 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 type { AsyncCallback, Callback } from './@ohos.base'; 22 23/** 24 * Provides the capabilities to control cloud file synchronization. 25 * 26 * @namespace cloudSync 27 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 28 * @since 11 29 */ 30declare namespace cloudSync { 31 /** 32 * Describes the Sync state type. 33 * 34 * @enum { number } 35 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 36 * @systemapi 37 * @since 10 38 */ 39 enum SyncState { 40 /** 41 * Indicates that the sync state is uploading. 42 * 43 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 44 * @systemapi 45 * @since 10 46 */ 47 UPLOADING, 48 /** 49 * Indicates that the sync failed in upload processing. 50 * 51 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 52 * @systemapi 53 * @since 10 54 */ 55 UPLOAD_FAILED, 56 /** 57 * Indicates that the sync state is downloading. 58 * 59 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 60 * @systemapi 61 * @since 10 62 */ 63 DOWNLOADING, 64 /** 65 * Indicates that the sync failed in download processing. 66 * 67 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 68 * @systemapi 69 * @since 10 70 */ 71 DOWNLOAD_FAILED, 72 /** 73 * Indicates that the sync finish. 74 * 75 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 76 * @systemapi 77 * @since 10 78 */ 79 COMPLETED, 80 /** 81 * Indicates that the sync has been stopped. 82 * 83 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 84 * @systemapi 85 * @since 10 86 */ 87 STOPPED 88 } 89 90 /** 91 * Describes the Sync Error type. 92 * 93 * @enum { number } 94 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 95 * @systemapi 96 * @since 10 97 */ 98 enum ErrorType { 99 /** 100 * No error occurred. 101 * 102 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 103 * @systemapi 104 * @since 10 105 */ 106 NO_ERROR, 107 /** 108 * Synchronization aborted due to network unavailable. 109 * 110 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 111 * @systemapi 112 * @since 10 113 */ 114 NETWORK_UNAVAILABLE, 115 /** 116 * Synchronization aborted due to wifi unavailable. 117 * 118 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 119 * @systemapi 120 * @since 10 121 */ 122 WIFI_UNAVAILABLE, 123 /** 124 * Synchronization aborted due to low capacity level. 125 * 126 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 127 * @systemapi 128 * @since 10 129 */ 130 BATTERY_LEVEL_LOW, 131 /** 132 * Synchronization aborted due to warning low capacity level. 133 * 134 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 135 * @systemapi 136 * @since 10 137 */ 138 BATTERY_LEVEL_WARNING, 139 /** 140 * Synchronization aborted due to cloud storage is full. 141 * 142 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 143 * @systemapi 144 * @since 10 145 */ 146 CLOUD_STORAGE_FULL, 147 /** 148 * Synchronization aborted due to local storage is full. 149 * 150 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 151 * @systemapi 152 * @since 10 153 */ 154 LOCAL_STORAGE_FULL 155 } 156 157 /** 158 * The SyncProgress data structure. 159 * 160 * @interface SyncProgress 161 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 162 * @systemapi 163 * @since 10 164 */ 165 interface SyncProgress { 166 /** 167 * The current sync state. 168 * 169 * @type { SyncState } 170 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 171 * @systemapi 172 * @since 10 173 */ 174 state: SyncState; 175 /** 176 * The error type of sync. 177 * 178 * @type { ErrorType } 179 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 180 * @systemapi 181 * @since 10 182 */ 183 error: ErrorType; 184 } 185 186 /** 187 * GallerySync object. 188 * 189 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 190 * @systemapi 191 * @since 10 192 */ 193 class GallerySync { 194 /** 195 * A constructor used to create a GallerySync object. 196 * 197 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 198 * @systemapi 199 * @since 10 200 */ 201 constructor(); 202 /** 203 * Subscribes to sync progress change event. This method uses a callback to get sync progress changes. 204 * 205 * @permission ohos.permission.CLOUDFILE_SYNC 206 * @param { 'progress' } evt - event type. 207 * @param { function } callback - callback function with a `SyncProgress` argument. 208 * @throws { BusinessError } 201 - Permission verification failed. 209 * @throws { BusinessError } 202 - The caller is not a system application. 210 * @throws { BusinessError } 401 - The input parameter is invalid. 211 * @throws { BusinessError } 13600001 - IPC error 212 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 213 * @systemapi 214 * @since 10 215 */ 216 on(evt: 'progress', callback: (pg: SyncProgress) => void): void; 217 /** 218 * Unsubscribes from sync progress event. 219 * 220 * @permission ohos.permission.CLOUDFILE_SYNC 221 * @param { 'progress' } evt - event type. 222 * @param { function } callback - callback function with a `SyncProgress` argument. 223 * @throws { BusinessError } 201 - Permission verification failed. 224 * @throws { BusinessError } 202 - The caller is not a system application. 225 * @throws { BusinessError } 401 - The input parameter is invalid. 226 * @throws { BusinessError } 13600001 - IPC error 227 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 228 * @systemapi 229 * @since 10 230 */ 231 off(evt: 'progress', callback: (pg: SyncProgress) => void): void; 232 /** 233 * Unsubscribes all callbacks objects from sync progress event. 234 * 235 * @permission ohos.permission.CLOUDFILE_SYNC 236 * @param { 'progress' } evt - event type. 237 * @throws { BusinessError } 201 - Permission verification failed. 238 * @throws { BusinessError } 202 - The caller is not a system application. 239 * @throws { BusinessError } 401 - The input parameter is invalid. 240 * @throws { BusinessError } 13600001 - IPC error 241 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 242 * @systemapi 243 * @since 10 244 */ 245 off(evt: 'progress'): void; 246 /** 247 * Start the gallery sync task. 248 * 249 * @permission ohos.permission.CLOUDFILE_SYNC 250 * @returns { Promise<void> } - Return Promise. 251 * @throws { BusinessError } 201 - Permission verification failed. 252 * @throws { BusinessError } 202 - The caller is not a system application. 253 * @throws { BusinessError } 401 - The input parameter is invalid. 254 * @throws { BusinessError } 22400001 - Cloud status not ready. 255 * @throws { BusinessError } 22400002 - Network unavailable. 256 * @throws { BusinessError } 22400003 - Battery level warning. 257 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 258 * @systemapi 259 * @since 10 260 */ 261 start(): Promise<void>; 262 /** 263 * Start the gallery sync task with callback. 264 * 265 * @permission ohos.permission.CLOUDFILE_SYNC 266 * @param { AsyncCallback<void> } [callback] - Callback function. 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. 270 * @throws { BusinessError } 22400001 - Cloud status not ready. 271 * @throws { BusinessError } 22400002 - Network unavailable. 272 * @throws { BusinessError } 22400003 - Battery level warning. 273 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 274 * @systemapi 275 * @since 10 276 */ 277 start(callback: AsyncCallback<void>): void; 278 /** 279 * Stop the gallery sync task. 280 * 281 * @permission ohos.permission.CLOUDFILE_SYNC 282 * @returns { Promise<void> } - Return Promise. 283 * @throws { BusinessError } 201 - Permission verification failed. 284 * @throws { BusinessError } 202 - The caller is not a system application. 285 * @throws { BusinessError } 401 - The input parameter is invalid. 286 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 287 * @systemapi 288 * @since 10 289 */ 290 stop(): Promise<void>; 291 /** 292 * Stop the gallery sync task with callback. 293 * 294 * @permission ohos.permission.CLOUDFILE_SYNC 295 * @param { AsyncCallback<void> } [callback] - Callback function. 296 * @throws { BusinessError } 201 - Permission verification failed. 297 * @throws { BusinessError } 202 - The caller is not a system application. 298 * @throws { BusinessError } 401 - The input parameter is invalid. 299 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 300 * @systemapi 301 * @since 10 302 */ 303 stop(callback: AsyncCallback<void>): void; 304 } 305 306 /** 307 * Describes the State type of download. 308 * 309 * @enum { number } 310 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 311 * @since 11 312 */ 313 enum State { 314 /** 315 * Indicates that the download task in process now. 316 * 317 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 318 * @since 11 319 */ 320 RUNNING, 321 /** 322 * Indicates that the download task finished. 323 * 324 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 325 * @since 11 326 */ 327 COMPLETED, 328 /** 329 * Indicates that the download task failed. 330 * 331 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 332 * @since 11 333 */ 334 FAILED, 335 /** 336 * Indicates that the download task stopped. 337 * 338 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 339 * @since 11 340 */ 341 STOPPED 342 } 343 344 /** 345 * Describes the download Error type. 346 * 347 * @enum { number } 348 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 349 * @since 11 350 */ 351 enum DownloadErrorType { 352 /** 353 * No error occurred. 354 * 355 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 356 * @since 11 357 */ 358 NO_ERROR, 359 /** 360 * download aborted due to unknown error. 361 * 362 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 363 * @since 11 364 */ 365 UNKNOWN_ERROR, 366 /** 367 * download aborted due to network unavailable. 368 * 369 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 370 * @since 11 371 */ 372 NETWORK_UNAVAILABLE, 373 /** 374 * download aborted due to local storage is full. 375 * 376 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 377 * @since 11 378 */ 379 LOCAL_STORAGE_FULL, 380 /** 381 * download aborted due to content is not found in the cloud. 382 * 383 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 384 * @since 11 385 */ 386 CONTENT_NOT_FOUND, 387 /** 388 * download aborted due to frequent user requests. 389 * 390 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 391 * @since 11 392 */ 393 FREQUENT_USER_REQUESTS, 394 } 395 396 /** 397 * The DownloadProgress data structure. 398 * 399 * @interface DownloadProgress 400 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 401 * @since 11 402 */ 403 interface DownloadProgress { 404 /** 405 * The current download state. 406 * 407 * @type { State } 408 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 409 * @since 11 410 */ 411 state: State; 412 /** 413 * The processed data size for current file. 414 * 415 * @type { number } 416 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 417 * @since 11 418 */ 419 processed: number; 420 /** 421 * The size of current file. 422 * 423 * @type { number } 424 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 425 * @since 11 426 */ 427 size: number; 428 /** 429 * The uri of current file. 430 * 431 * @type { string } 432 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 433 * @since 11 434 */ 435 uri: string; 436 /** 437 * The error type of download. 438 * 439 * @type { DownloadErrorType } 440 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 441 * @since 11 442 */ 443 error: DownloadErrorType; 444 } 445 446 /** 447 * Download object. 448 * 449 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 450 * @systemapi 451 * @since 10 452 */ 453 class Download { 454 /** 455 * A constructor used to create a Download object. 456 * 457 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 458 * @systemapi 459 * @since 10 460 */ 461 constructor(); 462 /** 463 * Subscribes to download progress change event. This method uses a callback to get download progress changes. 464 * 465 * @permission ohos.permission.CLOUDFILE_SYNC 466 * @param { 'progress' } evt - event type. 467 * @param { function } callback - callback function with a `DownloadProgress` argument. 468 * @throws { BusinessError } 201 - Permission verification failed. 469 * @throws { BusinessError } 202 - The caller is not a system application. 470 * @throws { BusinessError } 401 - The input parameter is invalid. 471 * @throws { BusinessError } 13600001 - IPC error 472 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 473 * @systemapi 474 * @since 10 475 */ 476 on(evt: 'progress', callback: (pg: DownloadProgress) => void): void; 477 /** 478 * Unsubscribes from download progress event. 479 * 480 * @permission ohos.permission.CLOUDFILE_SYNC 481 * @param { 'progress' } evt - event type. 482 * @param { function } callback - callback function with a `DownloadProgress` argument. 483 * @throws { BusinessError } 201 - Permission verification failed. 484 * @throws { BusinessError } 202 - The caller is not a system application. 485 * @throws { BusinessError } 401 - The input parameter is invalid. 486 * @throws { BusinessError } 13600001 - IPC error 487 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 488 * @systemapi 489 * @since 10 490 */ 491 off(evt: 'progress', callback: (pg: DownloadProgress) => void): void; 492 /** 493 * Unsubscribes all callbacks objects from download progress event. 494 * 495 * @permission ohos.permission.CLOUDFILE_SYNC 496 * @param { 'progress' } evt - event type. 497 * @throws { BusinessError } 201 - Permission verification failed. 498 * @throws { BusinessError } 202 - The caller is not a system application. 499 * @throws { BusinessError } 401 - The input parameter is invalid. 500 * @throws { BusinessError } 13600001 - IPC error 501 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 502 * @systemapi 503 * @since 10 504 */ 505 off(evt: 'progress'): void; 506 /** 507 * Start the download task. 508 * 509 * @permission ohos.permission.CLOUDFILE_SYNC 510 * @param { string } uri - uri of file. 511 * @returns { Promise<void> } - Return Promise. 512 * @throws { BusinessError } 201 - Permission verification failed. 513 * @throws { BusinessError } 202 - The caller is not a system application. 514 * @throws { BusinessError } 401 - The input parameter is invalid. 515 * @throws { BusinessError } 13900002 - No such file or directory. 516 * @throws { BusinessError } 13900025 - No space left on device. 517 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 518 * @systemapi 519 * @since 10 520 */ 521 start(uri: string): Promise<void>; 522 /** 523 * Start the download task with callback. 524 * 525 * @permission ohos.permission.CLOUDFILE_SYNC 526 * @param { string } uri - uri of file. 527 * @param { AsyncCallback<void> } [callback] - Callback function. 528 * @throws { BusinessError } 201 - Permission verification failed. 529 * @throws { BusinessError } 202 - The caller is not a system application. 530 * @throws { BusinessError } 401 - The input parameter is invalid. 531 * @throws { BusinessError } 13900002 - No such file or directory. 532 * @throws { BusinessError } 13900025 - No space left on device. 533 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 534 * @systemapi 535 * @since 10 536 */ 537 start(uri: string, callback: AsyncCallback<void>): void; 538 /** 539 * Stop the download task. 540 * 541 * @permission ohos.permission.CLOUDFILE_SYNC 542 * @param { string } uri - uri of file. 543 * @returns { Promise<void> } - Return Promise. 544 * @throws { BusinessError } 201 - Permission verification failed. 545 * @throws { BusinessError } 202 - The caller is not a system application. 546 * @throws { BusinessError } 401 - The input parameter is invalid. 547 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 548 * @systemapi 549 * @since 10 550 */ 551 stop(uri: string): Promise<void>; 552 /** 553 * Stop the download task with callback. 554 * 555 * @permission ohos.permission.CLOUDFILE_SYNC 556 * @param { string } uri - uri of file. 557 * @param { AsyncCallback<void> } [callback] - Callback function. 558 * @throws { BusinessError } 201 - Permission verification failed. 559 * @throws { BusinessError } 202 - The caller is not a system application. 560 * @throws { BusinessError } 401 - The input parameter is invalid. 561 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 562 * @systemapi 563 * @since 10 564 */ 565 stop(uri: string, callback: AsyncCallback<void>): void; 566 } 567 568 /** 569 * FileSync object. 570 * 571 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 572 * @systemapi 573 * @since 11 574 */ 575 class FileSync { 576 /** 577 * A constructor used to create a FileSync object. 578 * 579 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 580 * @throws { BusinessError } 401 - The input parameter is invalid. 581 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 582 * @systemapi 583 * @since 11 584 */ 585 constructor(); 586 /** 587 * Subscribes to sync progress change event. This method uses a callback to get sync progress changes. 588 * 589 * @permission ohos.permission.CLOUDFILE_SYNC 590 * @param { 'progress' } event - event type. 591 * @param { Callback<SyncProgress> } callback - callback function with a `SyncProgress` argument. 592 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 593 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 594 * @throws { BusinessError } 401 - The input parameter is invalid. 595 * @throws { BusinessError } 13600001 - IPC error 596 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 597 * @systemapi 598 * @since 11 599 */ 600 on(event: 'progress', callback: Callback<SyncProgress>): void; 601 /** 602 * Unsubscribes from sync progress event. 603 * 604 * @permission ohos.permission.CLOUDFILE_SYNC 605 * @param { 'progress' } event - event type. 606 * @param { Callback<SyncProgress> } [callback] - callback function with a `SyncProgress` argument. 607 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 608 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 609 * @throws { BusinessError } 401 - The input parameter is invalid. 610 * @throws { BusinessError } 13600001 - IPC error 611 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 612 * @systemapi 613 * @since 11 614 */ 615 off(event: 'progress', callback?: Callback<SyncProgress>): void; 616 /** 617 * Start the file sync task. 618 * 619 * @permission ohos.permission.CLOUDFILE_SYNC 620 * @returns { Promise<void> } - Return Promise. 621 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 622 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 623 * @throws { BusinessError } 401 - The input parameter is invalid. 624 * @throws { BusinessError } 13600001 - IPC error. 625 * @throws { BusinessError } 22400001 - Cloud status not ready. 626 * @throws { BusinessError } 22400002 - Network unavailable. 627 * @throws { BusinessError } 22400003 - Battery level warning. 628 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 629 * @systemapi 630 * @since 11 631 */ 632 start(): Promise<void>; 633 /** 634 * Start the file sync task with callback. 635 * 636 * @permission ohos.permission.CLOUDFILE_SYNC 637 * @param { AsyncCallback<void> } callback - Callback function. 638 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 639 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 640 * @throws { BusinessError } 401 - The input parameter is invalid. 641 * @throws { BusinessError } 13600001 - IPC error. 642 * @throws { BusinessError } 22400001 - Cloud status not ready. 643 * @throws { BusinessError } 22400002 - Network unavailable. 644 * @throws { BusinessError } 22400003 - Battery level warning. 645 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 646 * @systemapi 647 * @since 11 648 */ 649 start(callback: AsyncCallback<void>): void; 650 /** 651 * Stop the file sync task. 652 * 653 * @permission ohos.permission.CLOUDFILE_SYNC 654 * @returns { Promise<void> } - Return Promise. 655 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 656 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 657 * @throws { BusinessError } 401 - The input parameter is invalid. 658 * @throws { BusinessError } 13600001 - IPC error. 659 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 660 * @systemapi 661 * @since 11 662 */ 663 stop(): Promise<void>; 664 /** 665 * Stop the file sync task with callback. 666 * 667 * @permission ohos.permission.CLOUDFILE_SYNC 668 * @param { AsyncCallback<void> } callback - Callback function. 669 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 670 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 671 * @throws { BusinessError } 401 - The input parameter is invalid. 672 * @throws { BusinessError } 13600001 - IPC error. 673 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 674 * @systemapi 675 * @since 11 676 */ 677 stop(callback: AsyncCallback<void>): void; 678 /** 679 * Get the last synchronization time. 680 * 681 * @permission ohos.permission.CLOUDFILE_SYNC 682 * @returns { Promise<number> } - Return the date of last synchronization. 683 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 684 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 685 * @throws { BusinessError } 401 - The input parameter is invalid. 686 * @throws { BusinessError } 13600001 - IPC error. 687 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 688 * @systemapi 689 * @since 11 690 */ 691 getLastSyncTime(): Promise<number>; 692 /** 693 * Get the last synchronization time. 694 * 695 * @permission ohos.permission.CLOUDFILE_SYNC 696 * @param { AsyncCallback<number> } callback - Callback function. 697 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 698 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 699 * @throws { BusinessError } 401 - The input parameter is invalid. 700 * @throws { BusinessError } 13600001 - IPC error. 701 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 702 * @systemapi 703 * @since 11 704 */ 705 getLastSyncTime(callback: AsyncCallback<number>): void; 706 } 707 /** 708 * CloudFileCache object. 709 * 710 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 711 * @since 11 712 */ 713 class CloudFileCache { 714 /** 715 * A constructor used to create a CloudFileCache object. 716 * 717 * @throws { BusinessError } 401 - The input parameter is invalid. 718 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 719 * @since 11 720 */ 721 constructor(); 722 /** 723 * Subscribes to cloud file cache download progress change event. This method uses a callback to get download progress changes. 724 * 725 * @param { 'progress' } event - event type. 726 * @param { Callback<DownloadProgress> } callback - callback function with a `DownloadProgress` argument. 727 * @throws { BusinessError } 401 - The input parameter is invalid. 728 * @throws { BusinessError } 13600001 - IPC error 729 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 730 * @since 11 731 */ 732 on(event: 'progress', callback: Callback<DownloadProgress>): void; 733 /** 734 * Unsubscribes from cloud file cache download progress event. 735 * 736 * @param { 'progress' } event - event type. 737 * @param { Callback<DownloadProgress> } [callback] - callback function with a `DownloadProgress` argument. 738 * @throws { BusinessError } 401 - The input parameter is invalid. 739 * @throws { BusinessError } 13600001 - IPC error 740 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 741 * @since 11 742 */ 743 off(event: 'progress', callback?: Callback<DownloadProgress>): void; 744 745 /** 746 * Start the cloud file cache download task. 747 * 748 * @param { string } uri - uri of file. 749 * @returns { Promise<void> } - Return Promise. 750 * @throws { BusinessError } 401 - The input parameter is invalid. 751 * @throws { BusinessError } 13600001 - IPC error. 752 * @throws { BusinessError } 13900002 - No such file or directory. 753 * @throws { BusinessError } 13900025 - No space left on device. 754 * @throws { BusinessError } 14000002 - Invalid uri. 755 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 756 * @since 11 757 */ 758 start(uri: string): Promise<void>; 759 /** 760 * Start the cloud file cache download task with callback. 761 * 762 * @param { string } uri - uri of file. 763 * @param { AsyncCallback<void> } callback - Callback function. 764 * @throws { BusinessError } 401 - The input parameter is invalid. 765 * @throws { BusinessError } 13600001 - IPC error. 766 * @throws { BusinessError } 13900002 - No such file or directory. 767 * @throws { BusinessError } 13900025 - No space left on device. 768 * @throws { BusinessError } 14000002 - Invalid uri. 769 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 770 * @since 11 771 */ 772 start(uri: string, callback: AsyncCallback<void>): void; 773 /** 774 * Stop the cloud file cache download task. 775 * 776 * @param { string } uri - uri of file. 777 * @returns { Promise<void> } - Return Promise. 778 * @throws { BusinessError } 401 - The input parameter is invalid. 779 * @throws { BusinessError } 13600001 - IPC error. 780 * @throws { BusinessError } 13900002 - No such file or directory. 781 * @throws { BusinessError } 14000002 - Invalid uri. 782 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 783 * @since 11 784 */ 785 stop(uri: string): Promise<void>; 786 /** 787 * Stop the cloud file cache download task with callback. 788 * 789 * @param { string } uri - uri of file. 790 * @param { AsyncCallback<void> } callback - Callback function. 791 * @throws { BusinessError } 401 - The input parameter is invalid. 792 * @throws { BusinessError } 13600001 - IPC error. 793 * @throws { BusinessError } 13900002 - No such file or directory. 794 * @throws { BusinessError } 14000002 - Invalid uri. 795 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 796 * @since 11 797 */ 798 stop(uri: string, callback: AsyncCallback<void>): void; 799 /** 800 * Clean the local file cache. 801 * 802 * @permission ohos.permission.CLOUDFILE_SYNC 803 * @param { string } uri - uri of file. 804 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 805 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 806 * @throws { BusinessError } 401 - The input parameter is invalid. 807 * @throws { BusinessError } 13600001 - IPC error. 808 * @throws { BusinessError } 13900002 - No such file or directory. 809 * @throws { BusinessError } 14000002 - Invalid uri. 810 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 811 * @systemapi 812 * @since 11 813 */ 814 cleanCache(uri: string): void; 815 } 816 817 /** 818 * Describes the sync state of file. 819 * 820 * @enum { number } 821 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 822 * @systemapi 823 * @since 11 824 */ 825 enum FileSyncState { 826 /** 827 * Indicates that the file cache is uploading now. 828 * 829 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 830 * @systemapi 831 * @since 11 832 */ 833 UPLOADING, 834 /** 835 * Indicates that the file cache is downloading now. 836 * 837 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 838 * @systemapi 839 * @since 11 840 */ 841 DOWNLOADING, 842 /** 843 * Indicates that the file cache sync task finished. 844 * 845 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 846 * @systemapi 847 * @since 11 848 */ 849 COMPLETED, 850 /** 851 * Indicates that the file cache sync task stopped. 852 * 853 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 854 * @systemapi 855 * @since 11 856 */ 857 STOPPED 858 } 859 860 /** 861 * Get the sync state of file. 862 * 863 * @permission ohos.permission.CLOUDFILE_SYNC 864 * @param { Array<string> } uri - uri of files. 865 * @returns { Promise<Array<FileSyncState>> } - Return the sync state of given files. 866 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 867 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 868 * @throws { BusinessError } 401 - The input parameter is invalid. 869 * @throws { BusinessError } 13600001 - IPC error. 870 * @throws { BusinessError } 13900002 - No such file or directory. 871 * @throws { BusinessError } 14000002 - Invalid uri. 872 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 873 * @systemapi 874 * @since 11 875 */ 876 function getFileSyncState(uri: Array<string>): Promise<Array<FileSyncState>>; 877 /** 878 * Get the sync state of file. 879 * 880 * @permission ohos.permission.CLOUDFILE_SYNC 881 * @param { Array<string> } uri - uri of file. 882 * @param { AsyncCallback<Array<FileSyncState>> } callback - The callback is used to return the sync state of given files. 883 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 884 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 885 * @throws { BusinessError } 401 - The input parameter is invalid. 886 * @throws { BusinessError } 13600001 - IPC error. 887 * @throws { BusinessError } 13900002 - No such file or directory. 888 * @throws { BusinessError } 14000002 - Invalid uri. 889 * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core 890 * @systemapi 891 * @since 11 892 */ 893 function getFileSyncState(uri: Array<string>, callback: AsyncCallback<Array<FileSyncState>>): void; 894} 895 896export default cloudSync; 897