• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     * Synchronization aborted due to device temperature is too high.
157     *
158     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
159     * @systemapi
160     * @since 12
161     */
162    DEVICE_TEMPERATURE_TOO_HIGH,
163
164  }
165
166  /**
167   * The SyncProgress data structure.
168   *
169   * @interface SyncProgress
170   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
171   * @systemapi
172   * @since 10
173   */
174  interface SyncProgress {
175    /**
176     * The current sync state.
177     *
178     * @type { SyncState }
179     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
180     * @systemapi
181     * @since 10
182     */
183    state: SyncState;
184    /**
185     * The error type of sync.
186     *
187     * @type { ErrorType }
188     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
189     * @systemapi
190     * @since 10
191     */
192    error: ErrorType;
193  }
194
195  /**
196   * GallerySync object.
197   *
198   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
199   * @systemapi
200   * @since 10
201   */
202  class GallerySync {
203    /**
204     * A constructor used to create a GallerySync object.
205     *
206     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
207     * @systemapi
208     * @since 10
209     */
210    constructor();
211    /**
212     * Subscribes to sync progress change event. This method uses a callback to get sync progress changes.
213     *
214     * @permission ohos.permission.CLOUDFILE_SYNC
215     * @param { 'progress' } evt - event type.
216     * @param { function } callback - callback function with a `SyncProgress` argument.
217     * @throws { BusinessError } 201 - Permission verification failed.
218     * @throws { BusinessError } 202 - The caller is not a system application.
219     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
220     * <br>2.Incorrect parameter types.
221     * @throws { BusinessError } 13600001 - IPC error
222     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
223     * @systemapi
224     * @since 10
225     */
226    on(evt: 'progress', callback: (pg: SyncProgress) => void): void;
227    /**
228     * Unsubscribes from sync progress event.
229     *
230     * @permission ohos.permission.CLOUDFILE_SYNC
231     * @param { 'progress' } evt - event type.
232     * @param { function } callback - callback function with a `SyncProgress` argument.
233     * @throws { BusinessError } 201 - Permission verification failed.
234     * @throws { BusinessError } 202 - The caller is not a system application.
235     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
236     * <br>2.Incorrect parameter types.
237     * @throws { BusinessError } 13600001 - IPC error
238     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
239     * @systemapi
240     * @since 10
241     */
242    off(evt: 'progress', callback: (pg: SyncProgress) => void): void;
243    /**
244     * Unsubscribes all callbacks objects from sync progress event.
245     *
246     * @permission ohos.permission.CLOUDFILE_SYNC
247     * @param { 'progress' } evt - event type.
248     * @throws { BusinessError } 201 - Permission verification failed.
249     * @throws { BusinessError } 202 - The caller is not a system application.
250     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
251     * <br>2.Incorrect parameter types.
252     * @throws { BusinessError } 13600001 - IPC error
253     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
254     * @systemapi
255     * @since 10
256     */
257    off(evt: 'progress'): void;
258    /**
259     * Start the gallery sync task.
260     *
261     * @permission ohos.permission.CLOUDFILE_SYNC
262     * @returns { Promise<void> } - Return Promise.
263     * @throws { BusinessError } 201 - Permission verification failed.
264     * @throws { BusinessError } 202 - The caller is not a system application.
265     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Incorrect parameter types.
266     * @throws { BusinessError } 22400001 - Cloud status not ready.
267     * @throws { BusinessError } 22400002 - Network unavailable.
268     * @throws { BusinessError } 22400003 - Battery level warning.
269     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
270     * @systemapi
271     * @since 10
272     */
273    start(): Promise<void>;
274    /**
275     * Start the gallery sync task with callback.
276     *
277     * @permission ohos.permission.CLOUDFILE_SYNC
278     * @param { AsyncCallback<void> } [callback] - Callback function.
279     * @throws { BusinessError } 201 - Permission verification failed.
280     * @throws { BusinessError } 202 - The caller is not a system application.
281     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
282     * <br>2.Incorrect parameter types.
283     * @throws { BusinessError } 22400001 - Cloud status not ready.
284     * @throws { BusinessError } 22400002 - Network unavailable.
285     * @throws { BusinessError } 22400003 - Battery level warning.
286     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
287     * @systemapi
288     * @since 10
289     */
290    start(callback: AsyncCallback<void>): void;
291    /**
292     * Stop the gallery sync task.
293     *
294     * @permission ohos.permission.CLOUDFILE_SYNC
295     * @returns { Promise<void> } - Return Promise.
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.Possible causes:Incorrect parameter types.
299     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
300     * @systemapi
301     * @since 10
302     */
303    stop(): Promise<void>;
304    /**
305     * Stop the gallery sync task with callback.
306     *
307     * @permission ohos.permission.CLOUDFILE_SYNC
308     * @param { AsyncCallback<void> } [callback] - Callback function.
309     * @throws { BusinessError } 201 - Permission verification failed.
310     * @throws { BusinessError } 202 - The caller is not a system application.
311     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
312     * <br>2.Incorrect parameter types.
313     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
314     * @systemapi
315     * @since 10
316     */
317    stop(callback: AsyncCallback<void>): void;
318  }
319
320  /**
321   * Describes the State type of download.
322   *
323   * @enum { number }
324   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
325   * @since 11
326   */
327  enum State {
328    /**
329     * Indicates that the download task in process now.
330     *
331     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
332     * @since 11
333     */
334    RUNNING,
335    /**
336     * Indicates that the download task finished.
337     *
338     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
339     * @since 11
340     */
341    COMPLETED,
342    /**
343     * Indicates that the download task failed.
344     *
345     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
346     * @since 11
347     */
348    FAILED,
349    /**
350     * Indicates that the download task stopped.
351     *
352     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
353     * @since 11
354     */
355    STOPPED
356  }
357
358  /**
359   * Describes the download Error type.
360   *
361   * @enum { number }
362   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
363   * @since 11
364   */
365  enum DownloadErrorType {
366    /**
367     * No error occurred.
368     *
369     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
370     * @since 11
371     */
372    NO_ERROR,
373    /**
374     * download aborted due to unknown error.
375     *
376     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
377     * @since 11
378     */
379    UNKNOWN_ERROR,
380    /**
381     * download aborted due to network unavailable.
382     *
383     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
384     * @since 11
385     */
386    NETWORK_UNAVAILABLE,
387    /**
388     * download aborted due to local storage is full.
389     *
390     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
391     * @since 11
392     */
393    LOCAL_STORAGE_FULL,
394    /**
395     * download aborted due to content is not found in the cloud.
396     *
397     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
398     * @since 11
399     */
400    CONTENT_NOT_FOUND,
401    /**
402     * download aborted due to frequent user requests.
403     *
404     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
405     * @since 11
406     */
407    FREQUENT_USER_REQUESTS,
408  }
409
410  /**
411   * The DownloadProgress data structure.
412   *
413   * @interface DownloadProgress
414   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
415   * @since 11
416   */
417  interface DownloadProgress {
418    /**
419     * The current download state.
420     *
421     * @type { State }
422     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
423     * @since 11
424     */
425    state: State;
426    /**
427     * The processed data size for current file.
428     *
429     * @type { number }
430     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
431     * @since 11
432     */
433    processed: number;
434    /**
435     * The size of current file.
436     *
437     * @type { number }
438     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
439     * @since 11
440     */
441    size: number;
442    /**
443     * The uri of current file.
444     *
445     * @type { string }
446     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
447     * @since 11
448     */
449    uri: string;
450    /**
451     * The error type of download.
452     *
453     * @type { DownloadErrorType }
454     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
455     * @since 11
456     */
457    error: DownloadErrorType;
458  }
459
460  /**
461   * Download object.
462   *
463   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
464   * @systemapi
465   * @since 10
466   */
467  class Download {
468    /**
469     * A constructor used to create a Download object.
470     *
471     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
472     * @systemapi
473     * @since 10
474     */
475    constructor();
476    /**
477     * Subscribes to download progress change event. This method uses a callback to get download progress changes.
478     *
479     * @permission ohos.permission.CLOUDFILE_SYNC
480     * @param { 'progress' } evt - event type.
481     * @param { function } callback - callback function with a `DownloadProgress` argument.
482     * @throws { BusinessError } 201 - Permission verification failed.
483     * @throws { BusinessError } 202 - The caller is not a system application.
484     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
485     * <br>2.Incorrect parameter types.
486     * @throws { BusinessError } 13600001 - IPC error
487     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
488     * @systemapi
489     * @since 10
490     */
491    on(evt: 'progress', callback: (pg: DownloadProgress) => void): void;
492    /**
493     * Unsubscribes from download progress event.
494     *
495     * @permission ohos.permission.CLOUDFILE_SYNC
496     * @param { 'progress' } evt - event type.
497     * @param { function } callback - callback function with a `DownloadProgress` argument.
498     * @throws { BusinessError } 201 - Permission verification failed.
499     * @throws { BusinessError } 202 - The caller is not a system application.
500     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
501     * <br>2.Incorrect parameter types.
502     * @throws { BusinessError } 13600001 - IPC error
503     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
504     * @systemapi
505     * @since 10
506     */
507    off(evt: 'progress', callback: (pg: DownloadProgress) => void): void;
508    /**
509     * Unsubscribes all callbacks objects from download progress event.
510     *
511     * @permission ohos.permission.CLOUDFILE_SYNC
512     * @param { 'progress' } evt - event type.
513     * @throws { BusinessError } 201 - Permission verification failed.
514     * @throws { BusinessError } 202 - The caller is not a system application.
515     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
516     * <br>2.Incorrect parameter types.
517     * @throws { BusinessError } 13600001 - IPC error
518     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
519     * @systemapi
520     * @since 10
521     */
522    off(evt: 'progress'): void;
523    /**
524     * Start the download task.
525     *
526     * @permission ohos.permission.CLOUDFILE_SYNC
527     * @param { string } uri - uri of file.
528     * @returns { Promise<void> } - Return Promise.
529     * @throws { BusinessError } 201 - Permission verification failed.
530     * @throws { BusinessError } 202 - The caller is not a system application.
531     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
532     * <br>2.Incorrect parameter types.
533     * @throws { BusinessError } 13900002 - No such file or directory.
534     * @throws { BusinessError } 13900025 - No space left on device.
535     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
536     * @systemapi
537     * @since 10
538     */
539    start(uri: string): Promise<void>;
540    /**
541     * Start the download task with callback.
542     *
543     * @permission ohos.permission.CLOUDFILE_SYNC
544     * @param { string } uri - uri of file.
545     * @param { AsyncCallback<void> } [callback] - Callback function.
546     * @throws { BusinessError } 201 - Permission verification failed.
547     * @throws { BusinessError } 202 - The caller is not a system application.
548     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
549     * <br>2.Incorrect parameter types.
550     * @throws { BusinessError } 13900002 - No such file or directory.
551     * @throws { BusinessError } 13900025 - No space left on device.
552     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
553     * @systemapi
554     * @since 10
555     */
556    start(uri: string, callback: AsyncCallback<void>): void;
557    /**
558     * Stop the download task.
559     *
560     * @permission ohos.permission.CLOUDFILE_SYNC
561     * @param { string } uri - uri of file.
562     * @returns { Promise<void> } - Return Promise.
563     * @throws { BusinessError } 201 - Permission verification failed.
564     * @throws { BusinessError } 202 - The caller is not a system application.
565     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
566     * <br>2.Incorrect parameter types.
567     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
568     * @systemapi
569     * @since 10
570     */
571    stop(uri: string): Promise<void>;
572    /**
573     * Stop the download task with callback.
574     *
575     * @permission ohos.permission.CLOUDFILE_SYNC
576     * @param { string } uri - uri of file.
577     * @param { AsyncCallback<void> } [callback] - Callback function.
578     * @throws { BusinessError } 201 - Permission verification failed.
579     * @throws { BusinessError } 202 - The caller is not a system application.
580     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
581     * <br>2.Incorrect parameter types.
582     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
583     * @systemapi
584     * @since 10
585     */
586    stop(uri: string, callback: AsyncCallback<void>): void;
587  }
588
589  /**
590   * FileSync object.
591   *
592   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
593   * @systemapi
594   * @since 11
595   */
596  class FileSync {
597    /**
598     * A constructor used to create a FileSync object.
599     *
600     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
601     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Incorrect parameter types.
602     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
603     * @systemapi
604     * @since 11
605     */
606    constructor();
607    /**
608     * A constructor used to create a FileSync object.
609     *
610     * @param { string } bundleName - Name of the bundle that need to synchronize and subscribe the sync progress event.
611     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
612     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
613     * <br>2.Incorrect parameter types.
614     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
615     * @systemapi
616     * @since 12
617     */
618    constructor(bundleName: string);
619    /**
620     * Subscribes to sync progress change event. This method uses a callback to get sync progress changes.
621     *
622     * @permission ohos.permission.CLOUDFILE_SYNC
623     * @param { 'progress' } event - event type.
624     * @param { Callback<SyncProgress> } callback - callback function with a `SyncProgress` argument.
625     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
626     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
627     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
628     * <br>2.Incorrect parameter types.
629     * @throws { BusinessError } 13600001 - IPC error
630     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
631     * @systemapi
632     * @since 11
633     */
634    on(event: 'progress', callback: Callback<SyncProgress>): void;
635    /**
636     * Unsubscribes from sync progress event.
637     *
638     * @permission ohos.permission.CLOUDFILE_SYNC
639     * @param { 'progress' } event - event type.
640     * @param { Callback<SyncProgress> } [callback] - callback function with a `SyncProgress` argument.
641     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
642     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
643     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types.
644     * @throws { BusinessError } 13600001 - IPC error
645     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
646     * @systemapi
647     * @since 11
648     */
649    off(event: 'progress', callback?: Callback<SyncProgress>): void;
650    /**
651     * Start 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.Possible causes:Incorrect parameter types.
658     * @throws { BusinessError } 13600001 - IPC error.
659     * @throws { BusinessError } 22400001 - Cloud status not ready.
660     * @throws { BusinessError } 22400002 - Network unavailable.
661     * @throws { BusinessError } 22400003 - Battery level warning.
662     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
663     * @systemapi
664     * @since 11
665     */
666    start(): Promise<void>;
667    /**
668     * Start the file sync task with callback.
669     *
670     * @permission ohos.permission.CLOUDFILE_SYNC
671     * @param { AsyncCallback<void> } callback - Callback function.
672     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
673     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
674     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;2.Incorrect parameter types.
675     * @throws { BusinessError } 13600001 - IPC error.
676     * @throws { BusinessError } 22400001 - Cloud status not ready.
677     * @throws { BusinessError } 22400002 - Network unavailable.
678     * @throws { BusinessError } 22400003 - Battery level warning.
679     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
680     * @systemapi
681     * @since 11
682     */
683    start(callback: AsyncCallback<void>): void;
684    /**
685     * Stop the file sync task.
686     *
687     * @permission ohos.permission.CLOUDFILE_SYNC
688     * @returns { Promise<void> } - Return Promise.
689     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
690     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
691     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Incorrect parameter types.
692     * @throws { BusinessError } 13600001 - IPC error.
693     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
694     * @systemapi
695     * @since 11
696     */
697    stop(): Promise<void>;
698    /**
699     * Stop the file sync task with callback.
700     *
701     * @permission ohos.permission.CLOUDFILE_SYNC
702     * @param { AsyncCallback<void> } callback - Callback function.
703     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
704     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
705     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
706     * <br>2.Incorrect parameter types.
707     * @throws { BusinessError } 13600001 - IPC error.
708     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
709     * @systemapi
710     * @since 11
711     */
712    stop(callback: AsyncCallback<void>): void;
713    /**
714     * Get the last synchronization time.
715     *
716     * @permission ohos.permission.CLOUDFILE_SYNC
717     * @returns { Promise<number> } - Return the date of last synchronization.
718     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
719     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
720     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Incorrect parameter types.
721     * @throws { BusinessError } 13600001 - IPC error.
722     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
723     * @systemapi
724     * @since 11
725     */
726    getLastSyncTime(): Promise<number>;
727    /**
728     * Get the last synchronization time.
729     *
730     * @permission ohos.permission.CLOUDFILE_SYNC
731     * @param { AsyncCallback<number> } callback - Callback function.
732     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
733     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
734     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
735     * <br>2.Incorrect parameter types.
736     * @throws { BusinessError } 13600001 - IPC error.
737     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
738     * @systemapi
739     * @since 11
740     */
741    getLastSyncTime(callback: AsyncCallback<number>): void;
742  }
743  /**
744   * CloudFileCache object.
745   *
746   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
747   * @since 11
748   */
749  class CloudFileCache {
750    /**
751     * A constructor used to create a CloudFileCache object.
752     *
753     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:Incorrect parameter types.
754     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
755     * @since 11
756     */
757    constructor();
758    /**
759     * Subscribes to cloud file cache download progress change event. This method uses a callback to get download progress changes.
760     *
761     * @param { 'progress' } event - event type.
762     * @param { Callback<DownloadProgress> } callback - callback function with a `DownloadProgress` argument.
763     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
764     * <br>2.Incorrect parameter types.
765     * @throws { BusinessError } 13600001 - IPC error
766     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
767     * @since 11
768     */
769    on(event: 'progress', callback: Callback<DownloadProgress>): void;
770    /**
771     * Unsubscribes from cloud file cache download progress event.
772     *
773     * @param { 'progress' } event - event type.
774     * @param { Callback<DownloadProgress> } [callback] - callback function with a `DownloadProgress` argument.
775     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
776     * <br>2.Incorrect parameter types.
777     * @throws { BusinessError } 13600001 - IPC error
778     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
779     * @since 11
780     */
781    off(event: 'progress', callback?: Callback<DownloadProgress>): void;
782
783    /**
784     * Start the cloud file cache download task.
785     *
786     * @param { string } uri - uri of file.
787     * @returns { Promise<void> } - Return Promise.
788     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
789     * <br>2.Incorrect parameter types.
790     * @throws { BusinessError } 13600001 - IPC error.
791     * @throws { BusinessError } 13900002 - No such file or directory.
792     * @throws { BusinessError } 13900025 - No space left on device.
793     * @throws { BusinessError } 14000002 - Invalid uri.
794     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
795     * @since 11
796     */
797    start(uri: string): Promise<void>;
798    /**
799     * Start the cloud file cache download task with callback.
800     *
801     * @param { string } uri - uri of file.
802     * @param { AsyncCallback<void> } callback - Callback function.
803     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
804     * <br>2.Incorrect parameter types.
805     * @throws { BusinessError } 13600001 - IPC error.
806     * @throws { BusinessError } 13900002 - No such file or directory.
807     * @throws { BusinessError } 13900025 - No space left on device.
808     * @throws { BusinessError } 14000002 - Invalid uri.
809     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
810     * @since 11
811     */
812    start(uri: string, callback: AsyncCallback<void>): void;
813    /**
814     * Stop the cloud file cache download task.
815     *
816     * @param { string } uri - uri of file.
817     * @returns { Promise<void> } - Return Promise.
818     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
819     * <br>2.Incorrect parameter types.
820     * @throws { BusinessError } 13600001 - IPC error.
821     * @throws { BusinessError } 13900002 - No such file or directory.
822     * @throws { BusinessError } 14000002 - Invalid uri.
823     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
824     * @since 11
825     */
826    /**
827     * Stop the cloud file cache download task.
828     *
829     * @param { string } uri - uri of file.
830     * @param { boolean } [needClean] - whether to delete the file that already downloaded.
831     * @returns { Promise<void> } - Return Promise.
832     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
833     * <br>2.Incorrect parameter types.
834     * @throws { BusinessError } 13600001 - IPC error.
835     * @throws { BusinessError } 13900002 - No such file or directory.
836     * @throws { BusinessError } 14000002 - Invalid uri.
837     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
838     * @since 12
839     */
840    stop(uri: string, needClean?: boolean): Promise<void>;
841    /**
842     * Stop the cloud file cache download task with callback.
843     *
844     * @param { string } uri - uri of file.
845     * @param { AsyncCallback<void> } callback - Callback function.
846     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
847     * <br>2.Incorrect parameter types.
848     * @throws { BusinessError } 13600001 - IPC error.
849     * @throws { BusinessError } 13900002 - No such file or directory.
850     * @throws { BusinessError } 14000002 - Invalid uri.
851     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
852     * @since 11
853     */
854    stop(uri: string, callback: AsyncCallback<void>): void;
855    /**
856     * Clean the local file cache.
857     *
858     * @permission ohos.permission.CLOUDFILE_SYNC
859     * @param { string } uri - uri of file.
860     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
861     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
862     * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
863     * <br>2.Incorrect parameter types.
864     * @throws { BusinessError } 13600001 - IPC error.
865     * @throws { BusinessError } 13900002 - No such file or directory.
866     * @throws { BusinessError } 14000002 - Invalid uri.
867     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
868     * @systemapi
869     * @since 11
870     */
871    cleanCache(uri: string): void;
872  }
873
874  /**
875   * Describes the sync state of file.
876   *
877   * @enum { number }
878   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
879   * @systemapi
880   * @since 11
881   */
882  enum FileSyncState {
883    /**
884     * Indicates that the file cache is uploading now.
885     *
886     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
887     * @systemapi
888     * @since 11
889     */
890    UPLOADING,
891    /**
892     * Indicates that the file cache is downloading now.
893     *
894     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
895     * @systemapi
896     * @since 11
897     */
898    DOWNLOADING,
899    /**
900     * Indicates that the file cache sync task finished.
901     *
902     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
903     * @systemapi
904     * @since 11
905     */
906    COMPLETED,
907    /**
908     * Indicates that the file cache sync task stopped.
909     *
910     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
911     * @systemapi
912     * @since 11
913     */
914    STOPPED,
915    /**
916     * Indicates that the file is waiting for upload.
917     *
918     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
919     * @systemapi
920     * @since 12
921     */
922    TO_BE_UPLOADED,
923    /**
924     * Indicates that the file has been already uploaded successfully.
925     *
926     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
927     * @systemapi
928     * @since 12
929     */
930    UPLOAD_SUCCESS,
931    /**
932     * Indicates that the file upload failure.
933     *
934     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
935     * @systemapi
936     * @since 12
937     */
938    UPLOAD_FAILURE,
939  }
940
941  /**
942   * Get the sync state of file.
943   *
944   * @permission ohos.permission.CLOUDFILE_SYNC
945   * @param { Array<string> } uri - uri of files.
946   * @returns { Promise<Array<FileSyncState>> } - Return the sync state of given files.
947   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
948   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
949   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
950   * <br>2.Incorrect parameter types.
951   * @throws { BusinessError } 13600001 - IPC error.
952   * @throws { BusinessError } 13900002 - No such file or directory.
953   * @throws { BusinessError } 14000002 - Invalid uri.
954   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
955   * @systemapi
956   * @since 11
957   */
958  function getFileSyncState(uri: Array<string>): Promise<Array<FileSyncState>>;
959  /**
960   * Get the sync state of file.
961   *
962   * @permission ohos.permission.CLOUDFILE_SYNC
963   * @param { Array<string> } uri - uri of file.
964   * @param { AsyncCallback<Array<FileSyncState>> } callback - The callback is used to return the sync state of given files.
965   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
966   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
967   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
968   * <br>2.Incorrect parameter types.
969   * @throws { BusinessError } 13600001 - IPC error.
970   * @throws { BusinessError } 13900002 - No such file or directory.
971   * @throws { BusinessError } 14000002 - Invalid uri.
972   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
973   * @systemapi
974   * @since 11
975   */
976  function getFileSyncState(uri: Array<string>, callback: AsyncCallback<Array<FileSyncState>>): void;
977  /**
978   * Get the sync state of file.
979   *
980   * @param { string } uri - uri of file.
981   * @returns { FileSyncState } - return the sync state of given files.
982   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
983   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
984   * <br>2.Incorrect parameter types.
985   * @throws { BusinessError } 13900002 - No such file or directory.
986   * @throws { BusinessError } 13900004 - Interrupted system call
987   * @throws { BusinessError } 13900010 - Try again
988   * @throws { BusinessError } 13900012 - Permission denied by the file system
989   * @throws { BusinessError } 13900031 - Function not implemented
990   * @throws { BusinessError } 13900042 - Unknown error
991   * @throws { BusinessError } 14000002 - Invalid uri.
992   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
993   * @systemapi
994   * @since 12
995   */
996  function getFileSyncState(uri: string): FileSyncState;
997  /**
998   * Register change notify for the specified uri.
999   *
1000   * @param { string } uri - uri of file.
1001   * @param { boolean } recursion - Whether to monitor the child files.
1002   * @param { Callback<ChangeData> } callback - Returns the changed data.
1003   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
1004   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
1005   * <br>2.Incorrect parameter types.
1006   * @throws { BusinessError } 13900001 - Operation not permitted
1007   * @throws { BusinessError } 13900002 - No such file or directory.
1008   * @throws { BusinessError } 13900012 - Permission denied
1009   * @throws { BusinessError } 14000002 - Invalid uri.
1010   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1011   * @systemapi
1012   * @since 12
1013   */
1014  function registerChange(uri: string, recursion: boolean, callback: Callback<ChangeData>): void;
1015  /**
1016   * Unregister change notify fir the specified uri.
1017   *
1018   * @param { string } uri - uri of file.
1019   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
1020   * @throws { BusinessError } 401 - The input parameter is invalid.Possible causes:1.Mandatory parameters are left unspecified;
1021   * <br>2.Incorrect parameter types.
1022   * @throws { BusinessError } 13900001 - Operation not permitted
1023   * @throws { BusinessError } 13900002 - No such file or directory.
1024   * @throws { BusinessError } 13900012 - Permission denied
1025   * @throws { BusinessError } 14000002 - Invalid uri.
1026   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1027   * @systemapi
1028   * @since 12
1029   */
1030  function unregisterChange(uri: string): void;
1031
1032  /**
1033   * Enumeration types of data change.
1034   *
1035   * @enum { number } NotifyType
1036   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1037   * @systemapi
1038   * @since 12
1039   */
1040  enum NotifyType {
1041    /**
1042     * File has been newly created
1043     *
1044     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1045     * @systemapi
1046     * @since 12
1047     */
1048    NOTIFY_ADDED,
1049    /**
1050     * File has been modified.
1051     *
1052     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1053     * @systemapi
1054     * @since 12
1055     */
1056    NOTIFY_MODIFIED,
1057    /**
1058     * File has been deleted.
1059     *
1060     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1061     * @systemapi
1062     * @since 12
1063     */
1064    NOTIFY_DELETED,
1065    /**
1066     * File has been renamed or moved.
1067     *
1068     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1069     * @systemapi
1070     * @since 12
1071     */
1072    NOTIFY_RENAMED
1073  }
1074
1075  /**
1076   * Defines the change data
1077   *
1078   * @interface ChangeData
1079   * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1080   * @systemapi
1081   * @since 12
1082   */
1083  interface ChangeData {
1084    /**
1085     * The notify type of the change.
1086     *
1087     * @type {NotifyType}
1088     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1089     * @systemapi
1090     * @since 12
1091     */
1092    type: NotifyType;
1093    /**
1094     * Indicates whether the changed uri is directory.
1095     *
1096     * @type {Array<boolean>}
1097     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1098     * @systemapi
1099     * @since 12
1100     */
1101    isDirectory: Array<boolean>;
1102    /**
1103     * The changed uris.
1104     *
1105     * @type {Array<string>}
1106     * @syscap SystemCapability.FileManagement.DistributedFileService.CloudSync.Core
1107     * @systemapi
1108     * @since 12
1109     */
1110    uris: Array<string>;
1111  }
1112}
1113
1114export default cloudSync;
1115