• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2024 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 * Module providing backup and restore capabilities.
25 *
26 * @namespace backup
27 * @syscap SystemCapability.FileManagement.StorageService.Backup
28 * @systemapi
29 * @since 10
30 */
31declare namespace backup {
32  /**
33   * Corresponding to a file's metadata. FileMeta is useful when doing IPC with the backup service.
34   *
35   * @interface FileMeta
36   * @syscap SystemCapability.FileManagement.StorageService.Backup
37   * @systemapi
38   * @since 10
39   */
40  interface FileMeta {
41    /**
42     * Indicates the name of a bundle.
43     *
44     * @type { string }
45     * @syscap SystemCapability.FileManagement.StorageService.Backup
46     * @systemapi
47     * @since 10
48     */
49    bundleName: string;
50
51    /**
52     * Indicates a uri to a file.
53     *
54     * @type { string }
55     * @syscap SystemCapability.FileManagement.StorageService.Backup
56     * @systemapi
57     * @since 10
58     */
59    uri: string;
60  }
61
62  /**
63   * Corresponding to a file's data. Filedata is useful when doing IPC with the backup service.
64   *
65   * @interface FileData
66   * @syscap SystemCapability.FileManagement.StorageService.Backup
67   * @systemapi
68   * @since 10
69   */
70  interface FileData {
71    /**
72     * Indicates a native file descriptor typically retrieved from the backup service to hold the file's content.
73     *
74     * @type { number }
75     * @syscap SystemCapability.FileManagement.StorageService.Backup
76     * @systemapi
77     * @since 10
78     */
79    fd: number;
80  }
81
82  /**
83   * Save the time information of the incremental backup. IncrementalBackupTime is useful when doing IPC with the backup service.
84   *
85   * @interface IncrementalBackupTime
86   * @syscap SystemCapability.FileManagement.StorageService.Backup
87   * @systemapi
88   * @since 12
89   */
90  interface IncrementalBackupTime {
91    /**
92     * Indicates the name of a bundle.
93     *
94     * @type { string }
95     * @syscap SystemCapability.FileManagement.StorageService.Backup
96     * @systemapi
97     * @since 12
98     */
99    bundleName: string;
100
101    /**
102     * Time of the last incremental backup
103     *
104     * @type { number }
105     * @syscap SystemCapability.FileManagement.StorageService.Backup
106     * @systemapi
107     * @since 12
108     */
109    lastIncrementalTime: number;
110  }
111
112  /**
113   * Manifest file information in incremental data. FileManifestData is useful when doing IPC with the backup service.
114   *
115   * @interface FileManifestData
116   * @syscap SystemCapability.FileManagement.StorageService.Backup
117   * @systemapi
118   * @since 12
119   */
120  interface FileManifestData {
121    /**
122     * A file descriptor for the manifest file that holds the data
123     *
124     * @type { number }
125     * @syscap SystemCapability.FileManagement.StorageService.Backup
126     * @systemapi
127     * @since 12
128     */
129    manifestFd: number;
130  }
131
132  /**
133   * Provides configuration parameters for backup and restore.
134   *
135   * @interface BackupParams
136   * @syscap SystemCapability.FileManagement.StorageService.Backup
137   * @systemapi
138   * @since 12
139   */
140  interface BackupParams {
141    /**
142     * The optional parameters a json strings in the form of key value in backup or restore.
143     *
144     * @type { ?string }
145     * @syscap SystemCapability.FileManagement.StorageService.Backup
146     * @systemapi
147     * @since 12
148     */
149    parameters?: string;
150  }
151
152  /**
153   * Control backup and restore priority sequence
154   *
155   * @interface BackupPriority
156   * @syscap SystemCapability.FileManagement.StorageService.Backup
157   * @systemapi
158   * @since 12
159   */
160  interface BackupPriority {
161    /**
162     * Indicates the priority of a bundle.
163     *
164     * @type { ?number }
165     * @syscap SystemCapability.FileManagement.StorageService.Backup
166     * @systemapi
167     * @since 12
168     */
169    priority?: number;
170  }
171
172  /**
173   * Corresponds to an incremental application, including its last incremental time and incremental list.
174   *
175   * @extends IncrementalBackupTime, FileManifestData, BackupParams, BackupPriority
176   * @interface IncrementalBackupData
177   * @syscap SystemCapability.FileManagement.StorageService.Backup
178   * @systemapi
179   * @since 12
180   */
181  interface IncrementalBackupData extends IncrementalBackupTime, FileManifestData, BackupParams, BackupPriority {}
182
183  /**
184   * Corresponding to a file, including its metadata and data.
185   * File is useful when doing IPC with the backup service.
186   *
187   * @extends FileMeta, FileData, FileManifestData
188   * @interface File
189   * @syscap SystemCapability.FileManagement.StorageService.Backup
190   * @systemapi
191   * @since 10
192   */
193  /**
194   * Corresponds to a file, including its metadata and data and the file's manifest data.
195   * Files are useful as IPC and backup services.
196   *
197   * @extends FileMeta, FileData, FileManifestData
198   * @interface File
199   * @syscap SystemCapability.FileManagement.StorageService.Backup
200   * @systemapi
201   * @since 12
202   */
203  interface File extends FileMeta, FileData, FileManifestData {}
204
205  /**
206   * Obtain the backupVersion.
207   *
208   * @permission ohos.permission.BACKUP
209   * @returns { string } Return the backupVersion.
210   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
211   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
212   * @syscap SystemCapability.FileManagement.StorageService.Backup
213   * @systemapi
214   * @since 18
215   */
216  function getBackupVersion(): string;
217
218  /**
219   * Obtain a Json file that describes local capabilities.
220   *
221   * @permission ohos.permission.BACKUP
222   * @returns { Promise<FileData> } A FileData holding all the local capabilities. The returned file is a temporal file that will be
223   *     deleted automatically when closed.
224   * @throws { BusinessError } 13600001 - IPC error
225   * @throws { BusinessError } 13900005 - I/O error
226   * @throws { BusinessError } 13900011 - Out of memory
227   * @throws { BusinessError } 13900025 - No space left on device
228   * @throws { BusinessError } 13900042 - Unknown error
229   * @syscap SystemCapability.FileManagement.StorageService.Backup
230   * @systemapi
231   * @since 10
232   */
233  function getLocalCapabilities(): Promise<FileData>;
234
235  /**
236   * Obtain a Json file that describes local capabilities.
237   *
238   * @permission ohos.permission.BACKUP
239   * @param { AsyncCallback<FileData> } callback A callback method, the argument FileData will holding all the local capabilities.
240   *     The returned file is a temporal file that will be deleted automatically when closed.
241   * @throws { BusinessError } 13600001 - IPC error
242   * @throws { BusinessError } 13900005 - I/O error
243   * @throws { BusinessError } 13900011 - Out of memory
244   * @throws { BusinessError } 13900025 - No space left on device
245   * @throws { BusinessError } 13900042 - Unknown error
246   * @syscap SystemCapability.FileManagement.StorageService.Backup
247   * @systemapi
248   * @since 10
249   */
250  function getLocalCapabilities(callback: AsyncCallback<FileData>): void;
251
252  /**
253   * Obtain a json file that describes local capabilities.
254   *
255   * @permission ohos.permission.BACKUP
256   * @param { Array<IncrementalBackupTime> } dataList
257   * @returns { Promise<FileData> } A FileData holding all the local capabilities. The returned file is a temporal file that will be
258   * deleted automatically when closed.
259   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
260   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
261   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
262   * <br>2. Incorrect parameter types. 3.Parameter verification failed.
263   * @throws { BusinessError } 13600001 - IPC error
264   * @throws { BusinessError } 13900005 - I/O error
265   * @throws { BusinessError } 13900011 - Out of memory
266   * @throws { BusinessError } 13900025 - No space left on device
267   * @throws { BusinessError } 13900042 - Unknown error
268   * @syscap SystemCapability.FileManagement.StorageService.Backup
269   * @systemapi
270   * @since 12
271   */
272  function getLocalCapabilities(dataList: Array<IncrementalBackupTime>): Promise<FileData>;
273
274  /**
275    * Get Backup information from bundle.
276    *
277    * @permission ohos.permission.BACKUP
278    * @param { string } bundleToBackup Bundle to backup.
279    * @returns { string } Return the backup application's info.
280    * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
281    * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
282    * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
283    * <br>2. Incorrect parameter types. 3.Parameter verification failed.
284    * @syscap SystemCapability.FileManagement.StorageService.Backup
285    * @systemapi
286    * @since 12
287    */
288  function getBackupInfo(bundleToBackup: string): string;
289
290  /**
291   * Update backup or restore timeout.
292   *
293   * @permission ohos.permission.BACKUP
294   * @param { string } bundleName set update to bundleName app.
295   * @param { number } timeout Update backup or restore timeout(unit:ms).
296   * @returns { boolean } Return update result, true is success, false is fail.
297   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
298   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
299   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
300   * <br>2. Incorrect parameter types. 3.Parameter verification failed.
301   * @syscap SystemCapability.FileManagement.StorageService.Backup
302   * @systemapi
303   * @since 12
304   */
305  function updateTimer(bundleName: string, timeout: number): boolean;
306
307  /**
308   * Update send file fd rate.
309   *
310   * @permission ohos.permission.BACKUP
311   * @param { string } bundleName set update to bundleName app.
312   * @param { number } sendRate set send file fd rate.
313   * @returns { boolean } Return update result, true is success, false is fail.
314   * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
315   * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
316   * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
317   * <br>2. Incorrect parameter types. 3.Parameter verification failed.
318   * @syscap SystemCapability.FileManagement.StorageService.Backup
319   * @systemapi
320   * @since 12
321  */
322  function updateSendRate(bundleName: string, sendRate: number): boolean;
323
324  /**
325   * function that returns backup datasize by bundleName.
326   *
327   * @typedef {function} OnBackupSizeReport
328   * @param {string} reportInfo -the scanned backup datasize infos.
329   * @syscap SystemCapability.FileManagement.StorageService.Backup
330   * @systemapi
331   * @since 18
332   */
333   type OnBackupSizeReport = (reportInfo: string) => void;
334
335  /**
336   * General callbacks for both backup and restore procedure.
337   * The backup service will notify the client by these callbacks.
338   *
339   * @interface GeneralCallbacks
340   * @syscap SystemCapability.FileManagement.StorageService.Backup
341   * @systemapi
342   * @since 10
343   */
344  interface GeneralCallbacks {
345    /**
346     * Callback called when the backup service tries to send files to the client.
347     * The File argument indicates a file to send to the client.
348     *     The returned file is owned by the backup service and will be cleaned by the service once the file is closed.
349     *
350     * @type { AsyncCallback<File> }
351     * @throws { BusinessError } 13600001 - IPC error
352     * @throws { BusinessError } 13900005 - I/O error
353     * @throws { BusinessError } 13900011 - Out of memory
354     * @throws { BusinessError } 13900020 - Invalid argument
355     * @throws { BusinessError } 13900025 - No space left on device
356     * @throws { BusinessError } 13900042 - Unknown error
357     * @syscap SystemCapability.FileManagement.StorageService.Backup
358     * @systemapi
359     * @since 10
360     */
361    onFileReady: AsyncCallback<File>;
362
363    /**
364     * Callback called when a backup/restore procedure for an bundle is started.
365     * The return string argument indicates the name of the bundle.
366     *
367     * @throws { BusinessError } 13600001 - IPC error
368     * @throws { BusinessError } 13900005 - I/O error
369     * @throws { BusinessError } 13900011 - Out of memory
370     * @throws { BusinessError } 13900020 - Invalid argument
371     * @throws { BusinessError } 13900025 - No space left on device
372     * @throws { BusinessError } 13900042 - Unknown error
373     * @syscap SystemCapability.FileManagement.StorageService.Backup
374     * @systemapi
375     * @since 10
376     */
377    /**
378     * Callback called when a backup/restore procedure for an bundle is started.
379     * The first return string parameter indicates the name of the bundle.
380     * The second return string parameter indicates that when BusinessError errors occur,
381     * the callback data is the name of the bundle.
382     *
383     * @type { AsyncCallback<string, void | string> }
384     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
385     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
386     * @throws { BusinessError } 13500001 - The application is not added to the backup or restore
387     * @throws { BusinessError } 13500002 - Failed to start application extension Procedure
388     * @throws { BusinessError } 13600001 - IPC error
389     * @throws { BusinessError } 13900005 - I/O error
390     * @throws { BusinessError } 13900011 - Out of memory
391     * @throws { BusinessError } 13900025 - No space left on device
392     * @throws { BusinessError } 13900042 - Unknown error
393     * @syscap SystemCapability.FileManagement.StorageService.Backup
394     * @systemapi
395     * @since 12
396     */
397    onBundleBegin: AsyncCallback<string, void | string>;
398
399    /**
400     * Callback called when a backup/restore procedure for an bundle ends successfully or gets aborted unexpectedly.
401     * The return string argument indicates the name of the bundle.
402     *
403     * @throws { BusinessError } 13600001 - IPC error
404     * @throws { BusinessError } 13900005 - I/O error
405     * @throws { BusinessError } 13900011 - Out of memory
406     * @throws { BusinessError } 13900020 - Invalid argument
407     * @throws { BusinessError } 13900025 - No space left on device
408     * @throws { BusinessError } 13900042 - Unknown error
409     * @syscap SystemCapability.FileManagement.StorageService.Backup
410     * @systemapi
411     * @since 10
412     */
413    /**
414     * Callback called when a backup/restore procedure for an bundle ends successfully or gets aborted unexpectedly.
415     * The first return string parameter indicates the name of the bundle.
416     * The second return string parameter indicates that when BusinessError errors occur,
417     * the callback data is the name of the bundle.
418     *
419     * @type { AsyncCallback<string, void | string> }
420     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
421     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
422     * @throws { BusinessError } 13500003 - Backup or restore timed out
423     * @throws { BusinessError } 13500004 - Application extension death
424     * @throws { BusinessError } 13600001 - IPC error
425     * @throws { BusinessError } 13900005 - I/O error
426     * @throws { BusinessError } 13900011 - Out of memory
427     * @throws { BusinessError } 13900025 - No space left on device
428     * @throws { BusinessError } 13900042 - Unknown error
429     * @syscap SystemCapability.FileManagement.StorageService.Backup
430     * @systemapi
431     * @since 12
432     */
433    onBundleEnd: AsyncCallback<string, void | string>;
434
435    /**
436     * Callback called when the all the bundles to backup/restore are done or aborted unexpectedly.
437     *
438     * @type { AsyncCallback<undefined> }
439     * @throws { BusinessError } 13600001 - IPC error
440     * @throws { BusinessError } 13900005 - I/O error
441     * @throws { BusinessError } 13900011 - Out of memory
442     * @throws { BusinessError } 13900020 - Invalid argument
443     * @throws { BusinessError } 13900025 - No space left on device
444     * @throws { BusinessError } 13900042 - Unknown error
445     * @syscap SystemCapability.FileManagement.StorageService.Backup
446     * @systemapi
447     * @since 10
448     */
449    onAllBundlesEnd: AsyncCallback<undefined>;
450
451    /**
452     * Callback called when the backup service dies unexpectedly.
453     *
454     * @type { Callback<undefined> }
455     * @syscap SystemCapability.FileManagement.StorageService.Backup
456     * @systemapi
457     * @since 10
458     */
459    onBackupServiceDied: Callback<undefined>;
460
461    /**
462     * Callback called when the backup service return result information.
463     * The first return string parameter indicates the bundleName that triggers the callback.
464     * The second return string parameter indicates the result of the bundle.
465     *
466     * @param { string } bundleName the bundleName that triggers the callback.
467     * @param { string } result the result of the bundle.
468     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
469     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
470     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
471     * @throws { BusinessError } 13600001 - IPC error
472     * @throws { BusinessError } 13900005 - I/O error
473     * @throws { BusinessError } 13900011 - Out of memory
474     * @throws { BusinessError } 13900025 - No space left on device
475     * @throws { BusinessError } 13900042 - Unknown error
476     * @syscap SystemCapability.FileManagement.StorageService.Backup
477     * @systemapi
478     * @since 12
479     */
480    onResultReport(bundleName: string, result: string);
481
482    /**
483     * Callback called when the backup_sa service return result information.
484     * The first return string parameter indicates the result of the bundle.
485     *
486     * @param { string } bundleName the bundleName that triggers the callback.
487     * @param { string } process the process info of the bundle.
488     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
489     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
490     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
491     * @throws { BusinessError } 13500006 - Tar error
492     * @throws { BusinessError } 13500008 - Untar error
493     * @throws { BusinessError } 13600001 - IPC error
494     * @throws { BusinessError } 13900001 - Operation not permitted
495     * @throws { BusinessError } 13900005 - I/O error
496     * @throws { BusinessError } 13900011 - Out of memory
497     * @throws { BusinessError } 13900020 - Invalid argument
498     * @throws { BusinessError } 13900025 - No space left on device
499     * @syscap SystemCapability.FileManagement.StorageService.Backup
500     * @systemapi
501     * @since 12
502     */
503    onProcess(bundleName: string, process: string);
504
505    /**
506     * Callback called when the backup_sa service return result information.
507     * The first return string parameter indicates the result of the scanned bundle datasize.
508     *
509     * @type {OnBackupSizeReport}.
510     * @syscap SystemCapability.FileManagement.StorageService.Backup
511     * @systemapi
512     * @since 18
513     */
514    onBackupSizeReport?: OnBackupSizeReport;
515  }
516
517  /**
518   * Control class for backup procedure.
519   *
520   * @syscap SystemCapability.FileManagement.StorageService.Backup
521   * @systemapi
522   * @since 10
523   */
524  class SessionBackup {
525    /**
526     * Constructor for obtaining the instance of the SessionBackup class.
527     *
528     * @permission ohos.permission.BACKUP
529     * @param { GeneralCallbacks } callbacks Callbacks to be registered for the backup.
530     * @syscap SystemCapability.FileManagement.StorageService.Backup
531     * @systemapi
532     * @since 10
533     */
534    constructor(callbacks: GeneralCallbacks);
535
536    /**
537     * Obtain a Json file that describes local capabilities.
538     *
539     * @permission ohos.permission.BACKUP
540     * @returns { Promise<FileData> } A FileData holding all the local capabilities. The returned file is a temporal file that will be
541     * deleted automatically when closed.
542     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
543     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
544     * @throws { BusinessError } 13600001 - IPC error
545     * @throws { BusinessError } 13900001 - Operation not permitted
546     * @throws { BusinessError } 13900020 - Invalid argument
547     * @throws { BusinessError } 13900042 - Internal error
548     * @syscap SystemCapability.FileManagement.StorageService.Backup
549     * @systemapi
550     * @since 18
551     */
552    getLocalCapabilities(): Promise<FileData>;
553
554    /**
555     * Obtain application data size to be backed up.
556     *
557     * @permission ohos.permission.BACKUP
558     * @param { boolean } isPreciseScan Indicates whether to obtain the exact data size.
559     * @param { Array<IncrementalBackupTime> } dataList Application list.
560     * @returns { Promise<void> } The promise returned by the function.
561     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
562     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
563     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
564     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
565     * @throws { BusinessError } 13600001 - IPC error
566     * @throws { BusinessError } 13900001 - Operation not permitted
567     * @throws { BusinessError } 13900020 - Invalid argument
568     * @throws { BusinessError } 13900042 - Internal error
569     * @syscap SystemCapability.FileManagement.StorageService.Backup
570     * @systemapi
571     * @since 18
572     */
573    getBackupDataSize(isPreciseScan: boolean, dataList: Array<IncrementalBackupTime>): Promise<void>;
574
575    /**
576     * Append new bundles to backup.
577     *
578     * @permission ohos.permission.BACKUP
579     * @param { string[] } bundlesToBackup Bundles to backup.
580     * @returns { Promise<void> } The promise returned by the function.
581     * @throws { BusinessError } 13600001 - IPC error
582     * @throws { BusinessError } 13900001 - Operation not permitted
583     * @throws { BusinessError } 13900005 - I/O error
584     * @throws { BusinessError } 13900011 - Out of memory
585     * @throws { BusinessError } 13900020 - Invalid argument
586     * @throws { BusinessError } 13900025 - No space left on device
587     * @throws { BusinessError } 13900042 - Unknown error
588     * @syscap SystemCapability.FileManagement.StorageService.Backup
589     * @systemapi
590     * @since 10
591     */
592    /**
593     * Append new bundles and backupInfos to backup.
594     *
595     * @permission ohos.permission.BACKUP
596     * @param { string[] } bundlesToBackup Bundles to backup.
597     * @param { string[] } infos Infos to backup.
598     * @returns { Promise<void> } The promise returned by the function.
599     * @throws { BusinessError } 13600001 - IPC error
600     * @throws { BusinessError } 13900001 - Operation not permitted
601     * @throws { BusinessError } 13900005 - I/O error
602     * @throws { BusinessError } 13900011 - Out of memory
603     * @throws { BusinessError } 13900020 - Invalid argument
604     * @throws { BusinessError } 13900025 - No space left on device
605     * @throws { BusinessError } 13900042 - Unknown error
606     * @syscap SystemCapability.FileManagement.StorageService.Backup
607     * @systemapi
608     * @since 12
609     */
610    appendBundles(bundlesToBackup: string[], infos?: string[]): Promise<void>;
611
612    /**
613     * Append new bundles to backup.
614     *
615     * @permission ohos.permission.BACKUP
616     * @param { string[] } bundlesToBackup Bundles to backup.
617     * @param { AsyncCallback<void> } callback Asynchronous callback to be called when appendBundles has finished.
618     * @throws { BusinessError } 13600001 - IPC error
619     * @throws { BusinessError } 13900001 - Operation not permitted
620     * @throws { BusinessError } 13900005 - I/O error
621     * @throws { BusinessError } 13900011 - Out of memory
622     * @throws { BusinessError } 13900020 - Invalid argument
623     * @throws { BusinessError } 13900025 - No space left on device
624     * @throws { BusinessError } 13900042 - Unknown error
625     * @syscap SystemCapability.FileManagement.StorageService.Backup
626     * @systemapi
627     * @since 10
628     */
629    appendBundles(bundlesToBackup: string[], callback: AsyncCallback<void>): void;
630
631    /**
632     * End Backup process
633     *
634     * @permission ohos.permission.BACKUP
635     * @returns { Promise<void> } The promise returned by the function.
636     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
637     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
638     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
639     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
640     * @throws { BusinessError } 13600001 - IPC error
641     * @throws { BusinessError } 13900001 - Operation not permitted
642     * @throws { BusinessError } 13900005 - I/O error
643     * @throws { BusinessError } 13900042 - Unknown error
644     * @syscap SystemCapability.FileManagement.StorageService.Backup
645     * @systemapi
646     * @since 12
647     */
648    release(): Promise<void>;
649
650    /**
651     * cancel the application being backup.
652     *
653     * @permission ohos.permission.BACKUP
654     * @param { string } bundleName - Set the bundleName of the application to be canceled.
655     * @returns { number } Return cancel result, 0 is success, 13500011 is fail, 13500012 is not have task.
656     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
657     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
658     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
659     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
660     * @syscap SystemCapability.FileManagement.StorageService.Backup
661     * @systemapi
662     * @since 18
663     */
664    cancel(bundleName: string): number;
665
666     /**
667     * Provides an interface for the tool to clear temporary directories
668     *
669     * @permission ohos.permission.BACKUP
670     * @param { string } bundleName - Set the bundleName of the application to be cleaned.
671     * @returns { Promise<boolean> } Return clean result, true is success, false is fail.
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     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
675     * @syscap SystemCapability.FileManagement.StorageService.Backup
676     * @systemapi
677     * @since 20
678     */
679    cleanBundleTempDir(bundleName: string): Promise<boolean>;
680
681    /**
682     * Provides an interface for the tool to get compatibility info.
683     * @permission ohos.permission.BACKUP
684     * @param { string } bundleName - Set the bundleName of the application that need to get compatibilityInfo.
685     * @param { string } extInfo - Indicates the extension information of application.
686     * @returns { Promise<string> } Return compatibility info.
687     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
688     * @throws { BusinessError } 202 - Permission verification failed,
689     *     application which is not a system application uses system API.
690     * @syscap SystemCapability.FileManagement.StorageService.Backup
691     * @systemapi
692     * @since 20
693     */
694    getCompatibilityInfo(bundleName: string, extInfo: string): Promise<string>;
695  }
696
697  /**
698   * Control class for restore procedure.
699   *
700   * @syscap SystemCapability.FileManagement.StorageService.Backup
701   * @systemapi
702   * @since 10
703   */
704  class SessionRestore {
705    /**
706     * Constructor for obtaining the instance of the SessionBackup class.
707     *
708     * @permission ohos.permission.BACKUP
709     * @param { GeneralCallbacks } callbacks Callbacks to be registered for the restore.
710     * @syscap SystemCapability.FileManagement.StorageService.Backup
711     * @systemapi
712     * @since 10
713     */
714    constructor(callbacks: GeneralCallbacks);
715
716    /**
717     * Obtain a Json file that describes local capabilities.
718     *
719     * @permission ohos.permission.BACKUP
720     * @returns { Promise<FileData> } A FileData holding all the local capabilities. The returned file is a temporal file that will be
721     * deleted automatically when closed.
722     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
723     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
724     * @throws { BusinessError } 13600001 - IPC error
725     * @throws { BusinessError } 13900001 - Operation not permitted
726     * @throws { BusinessError } 13900020 - Invalid argument
727     * @throws { BusinessError } 13900042 - Internal error
728     * @syscap SystemCapability.FileManagement.StorageService.Backup
729     * @systemapi
730     * @since 18
731     */
732    getLocalCapabilities(): Promise<FileData>;
733
734    /**
735     * Append new bundles to be restore up during the restore.
736     *
737     * @permission ohos.permission.BACKUP
738     * @param { number } remoteCapabilitiesFd Opened JSON file that stores remote device capabilities.
739     *     You can use the getLocalCapabilities method to obtain the value.
740     * @param { string[] } bundlesToBackup Bundles to restore.
741     * @returns { Promise<void> } The promise returned by the function.
742     * @throws { BusinessError } 13600001 - IPC error
743     * @throws { BusinessError } 13900001 - Operation not permitted
744     * @throws { BusinessError } 13900005 - I/O error
745     * @throws { BusinessError } 13900011 - Out of memory
746     * @throws { BusinessError } 13900020 - Invalid argument
747     * @throws { BusinessError } 13900025 - No space left on device
748     * @throws { BusinessError } 13900042 - Unknown error
749     * @syscap SystemCapability.FileManagement.StorageService.Backup
750     * @systemapi
751     * @since 10
752     */
753    /**
754     * Append new bundles and restoreInfos to be restore up during the restore.
755     *
756     * @permission ohos.permission.BACKUP
757     * @param { number } remoteCapabilitiesFd Opened JSON file that stores remote device capabilities.
758     *     You can use the getLocalCapabilities method to obtain the value.
759     * @param { string[] } bundlesToBackup Bundles to restore.
760     * @param { string[] } [infos] infos to restore
761     * @returns { Promise<void> } The promise returned by the function.
762     * @throws { BusinessError } 13600001 - IPC error
763     * @throws { BusinessError } 13900001 - Operation not permitted
764     * @throws { BusinessError } 13900005 - I/O error
765     * @throws { BusinessError } 13900011 - Out of memory
766     * @throws { BusinessError } 13900020 - Invalid argument
767     * @throws { BusinessError } 13900025 - No space left on device
768     * @throws { BusinessError } 13900042 - Unknown error
769     * @syscap SystemCapability.FileManagement.StorageService.Backup
770     * @systemapi
771     * @since 12
772     */
773    appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], infos?: string[]): Promise<void>;
774
775    /**
776     * Append new bundles to be restore up during the restore.
777     *
778     * @permission ohos.permission.BACKUP
779     * @param { number } remoteCapabilitiesFd Opened JSON file that stores remote device capabilities.
780     *     You can use the getLocalCapabilities method to obtain the value.
781     * @param { string[] } bundlesToBackup Bundles to restore.
782     * @param { AsyncCallback<void> } callback Asynchronous callback to be called when appendBundles has finished.
783     * @throws { BusinessError } 13600001 - IPC error
784     * @throws { BusinessError } 13900001 - Operation not permitted
785     * @throws { BusinessError } 13900005 - I/O error
786     * @throws { BusinessError } 13900011 - Out of memory
787     * @throws { BusinessError } 13900020 - Invalid argument
788     * @throws { BusinessError } 13900025 - No space left on device
789     * @throws { BusinessError } 13900042 - Unknown error
790     * @syscap SystemCapability.FileManagement.StorageService.Backup
791     * @systemapi
792     * @since 10
793     */
794    appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback: AsyncCallback<void>): void;
795
796    /**
797     * Publish the file handle to the backup service to make the service aware that the file's content is ready.
798     * This interface is part of the zero-copy feature.
799     *
800     * @permission ohos.permission.BACKUP
801     * @param { FileMeta } fileMeta Metadata of the file to be sent. Make sure that the backup framework holds
802     *     this file by calling getFileHandle.
803     * @returns { Promise<void> } The promise returned by the function.
804     * @throws { BusinessError } 13600001 - IPC error
805     * @throws { BusinessError } 13900001 - Operation not permitted
806     * @throws { BusinessError } 13900020 - Invalid argument
807     * @throws { BusinessError } 13900042 - Unknown error
808     * @syscap SystemCapability.FileManagement.StorageService.Backup
809     * @systemapi
810     * @since 10
811     */
812    publishFile(fileMeta: FileMeta): Promise<void>;
813
814    /**
815     * Publish the file handle to the backup service to make the service aware that the file's content is ready.
816     * This interface is part of the zero-copy feature.
817     *
818     * @permission ohos.permission.BACKUP
819     * @param { FileMeta } fileMeta Metadata of the file to be sent. Make sure that the backup framework holds
820     *     this file by calling getFileHandle.
821     * @param { AsyncCallback<void> } callback Asynchronous callback to be called when publishFile has finished.
822     * @throws { BusinessError } 13600001 - IPC error
823     * @throws { BusinessError } 13900001 - Operation not permitted
824     * @throws { BusinessError } 13900020 - Invalid argument
825     * @throws { BusinessError } 13900042 - Unknown error
826     * @syscap SystemCapability.FileManagement.StorageService.Backup
827     * @systemapi
828     * @since 10
829     */
830    publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void;
831
832    /**
833     * Request to get a shared file from the service. This interface is part of the zero-copy feature.
834     * Developers could get the file through onFileReady callback.
835     * When the client accomplished the file, use publishFile to publish.
836     *
837     * @permission ohos.permission.BACKUP
838     * @param { FileMeta } fileMeta Metadata of the file to be sent. Note that all the files should come
839     *     from the backup procedure or the getLocalCapabilities method.
840     * @returns { Promise<void> } The promise returned by the function.
841     * @throws { BusinessError } 13600001 - IPC error
842     * @throws { BusinessError } 13900001 - Operation not permitted
843     * @throws { BusinessError } 13900020 - Invalid argument
844     * @throws { BusinessError } 13900042 - Unknown error
845     * @syscap SystemCapability.FileManagement.StorageService.Backup
846     * @systemapi
847     * @since 10
848     */
849    getFileHandle(fileMeta: FileMeta): Promise<void>;
850
851    /**
852     * Request to get a shared file from the service. This interface is part of the zero-copy feature.
853     * Developers could get the file through onFileReady callback.
854     * When the client accomplished the file, use publishFile to publish.
855     *
856     * @permission ohos.permission.BACKUP
857     * @param { FileMeta } fileMeta Metadata of the file to be sent. Note that all the files should come
858     *     from the backup procedure or the getLocalCapabilities method.
859     * @param { AsyncCallback<void> } callback Asynchronous callback to be called when getFileHandle has finished.
860     * @throws { BusinessError } 13600001 - IPC error
861     * @throws { BusinessError } 13900001 - Operation not permitted
862     * @throws { BusinessError } 13900020 - Invalid argument
863     * @throws { BusinessError } 13900042 - Unknown error
864     * @syscap SystemCapability.FileManagement.StorageService.Backup
865     * @systemapi
866     * @since 10
867     */
868    getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void;
869
870    /**
871     * End restore process
872     *
873     * @permission ohos.permission.BACKUP
874     * @returns { Promise<void> } The promise returned by the function.
875     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
876     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
877     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
878     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
879     * @throws { BusinessError } 13600001 - IPC error
880     * @throws { BusinessError } 13900001 - Operation not permitted
881     * @throws { BusinessError } 13900005 - I/O error
882     * @throws { BusinessError } 13900042 - Unknown error
883     * @syscap SystemCapability.FileManagement.StorageService.Backup
884     * @systemapi
885     * @since 12
886     */
887    release(): Promise<void>;
888
889    /**
890     * cancel the application being restore.
891     *
892     * @permission ohos.permission.BACKUP
893     * @param { string } bundleName - Set the bundleName of the application to be canceled.
894     * @returns { number } Return cancel result, 0 is success, 13500011 is fail, 13500012 is not have task.
895     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
896     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
897     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
898     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
899     * @syscap SystemCapability.FileManagement.StorageService.Backup
900     * @systemapi
901     * @since 18
902     */
903    cancel(bundleName: string): number;
904
905    /**
906     * Provides an interface for the tool to clear temporary directories
907     *
908     * @permission ohos.permission.BACKUP
909     * @param { string } bundleName - Set the bundleName of the application to be cleaned.
910     * @returns { Promise<boolean> } Return clean result, true is success, false is fail.
911     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
912     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
913     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
914     * @syscap SystemCapability.FileManagement.StorageService.Backup
915     * @systemapi
916     * @since 20
917     */
918    cleanBundleTempDir(bundleName: string): Promise<boolean>;
919
920    /**
921     * Provides an interface for the tool to get compatibility info.
922     * @permission ohos.permission.BACKUP
923     * @param { string } bundleName - Set the bundleName of the application that need to get compatibilityInfo.
924     * @param { string } extInfo - Indicates the extension information of application.
925     * @returns { Promise<string> } Return compatibility info.
926     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
927     * @throws { BusinessError } 202 - Permission verification failed,
928     *     application which is not a system application uses system API.
929     * @syscap SystemCapability.FileManagement.StorageService.Backup
930     * @systemapi
931     * @since 20
932     */
933    getCompatibilityInfo(bundleName: string, extInfo: string): Promise<string>;
934  }
935
936  /**
937   * Control class for incremental backup procedure.
938   *
939   * @syscap SystemCapability.FileManagement.StorageService.Backup
940   * @systemapi
941   * @since 12
942   */
943  class IncrementalBackupSession {
944    /**
945     * Constructor for obtaining the instance of the IncrementalBackupSession class.
946     *
947     * @permission ohos.permission.BACKUP
948     * @param { GeneralCallbacks } callbacks Callbacks to be registered for the backup.
949     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
950     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
951     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
952     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
953     * @syscap SystemCapability.FileManagement.StorageService.Backup
954     * @systemapi
955     * @since 12
956     */
957    constructor(callbacks: GeneralCallbacks);
958
959   /**
960     * Obtain a Json file that describes local capabilities.
961     *
962     * @permission ohos.permission.BACKUP
963     * @returns { Promise<FileData> } A FileData holding all the local capabilities. The returned file is a temporal file that will be
964     * deleted automatically when closed.
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 } 13600001 - IPC error
968     * @throws { BusinessError } 13900001 - Operation not permitted
969     * @throws { BusinessError } 13900020 - Invalid argument
970     * @throws { BusinessError } 13900042 - Internal error
971     * @syscap SystemCapability.FileManagement.StorageService.Backup
972     * @systemapi
973     * @since 18
974     */
975    getLocalCapabilities(): Promise<FileData>;
976
977    /**
978     * Obtain application data size to be backed up.
979     *
980     * @permission ohos.permission.BACKUP
981     * @param { boolean } isPreciseScan Indicates whether to obtain the exact data size.
982     * @param { Array<IncrementalBackupTime> } dataList Application list.
983     * @returns { Promise<void> } The promise returned by the function.
984     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
985     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
986     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
987     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
988     * @throws { BusinessError } 13600001 - IPC error
989     * @throws { BusinessError } 13900001 - Operation not permitted
990     * @throws { BusinessError } 13900020 - Invalid argument
991     * @throws { BusinessError } 13900042 - Internal error
992     * @syscap SystemCapability.FileManagement.StorageService.Backup
993     * @systemapi
994     * @since 18
995     */
996    getBackupDataSize(isPreciseScan: boolean, dataList: Array<IncrementalBackupTime>): Promise<void>;
997
998    /**
999     * Append new bundles to incremental backup.
1000     *
1001     * @permission ohos.permission.BACKUP
1002     * @param { Array<IncrementalBackupData> } bundlesToBackup Bundles to incremental backup.
1003     * @returns { Promise<void> } The promise returned by the function.
1004     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
1005     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
1006     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
1007     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
1008     * @throws { BusinessError } 13600001 - IPC error
1009     * @throws { BusinessError } 13900001 - Operation not permitted
1010     * @throws { BusinessError } 13900005 - I/O error
1011     * @throws { BusinessError } 13900011 - Out of memory
1012     * @throws { BusinessError } 13900025 - No space left on device
1013     * @throws { BusinessError } 13900042 - Unknown error
1014     * @syscap SystemCapability.FileManagement.StorageService.Backup
1015     * @systemapi
1016     * @since 12
1017     */
1018    appendBundles(bundlesToBackup: Array<IncrementalBackupData>): Promise<void>;
1019
1020    /**
1021     * Append new bundles to incremental backup.
1022     *
1023     * @permission ohos.permission.BACKUP
1024     * @param { Array<IncrementalBackupData> } bundlesToAppend Bundles to incremental backup.
1025     * @param { string[] } infos information of the bundlesToBackup
1026     * @returns { Promise<void> } The promise returned by the function.
1027     * @throws { BusinessError } 201 - Permission verification failed. This error code is usually the result returned by VerifyAccessToken.
1028     * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API.
1029     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
1030     * <br>2. Incorrect parameter types. 3. Parameter verification failed.
1031     * @throws { BusinessError } 13600001 - IPC error
1032     * @throws { BusinessError } 13900001 - Operation not permitted
1033     * @throws { BusinessError } 13900005 - I/O error
1034     * @throws { BusinessError } 13900011 - Out of memory
1035     * @throws { BusinessError } 13900025 - No space left on device
1036     * @throws { BusinessError } 13900042 - Unknown error
1037     * @syscap SystemCapability.FileManagement.StorageService.Backup
1038     * @systemapi
1039     * @since 12
1040     */
1041    appendBundles(bundlesToAppend: Array<IncrementalBackupData>, infos: string[]): Promise<void>;
1042
1043    /**
1044     * End backup process
1045     *
1046     * @permission ohos.permission.BACKUP
1047     * @returns { Promise<void> } The promise returned by the function.
1048     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
1049     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
1050     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
1051     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
1052     * @throws { BusinessError } 13600001 - IPC error
1053     * @throws { BusinessError } 13900001 - Operation not permitted
1054     * @throws { BusinessError } 13900005 - I/O error
1055     * @throws { BusinessError } 13900042 - Unknown error
1056     * @syscap SystemCapability.FileManagement.StorageService.Backup
1057     * @systemapi
1058     * @since 12
1059     */
1060    release(): Promise<void>;
1061
1062    /**
1063     * cancel the application being incrementalBackup.
1064     *
1065     * @permission ohos.permission.BACKUP
1066     * @param { string } bundleName - Set the bundleName of the application to be canceled.
1067     * @returns { number } Return cancel result, 0 is success, 13500011 is fail, 13500012 is not have task.
1068     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
1069     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
1070     * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified.
1071     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
1072     * @syscap SystemCapability.FileManagement.StorageService.Backup
1073     * @systemapi
1074     * @since 18
1075     */
1076    cancel(bundleName: string): number;
1077
1078    /**
1079     * Provides an interface for the tool to clear temporary directories
1080     *
1081     * @permission ohos.permission.BACKUP
1082     * @param { string } bundleName - Set the bundleName of the application to be cleaned.
1083     * @returns { Promise<boolean> } Return clean result, true is success, false is fail.
1084     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
1085     * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API.
1086     * <br>2. Incorrect parameter types. 3.Parameter verification failed.
1087     * @syscap SystemCapability.FileManagement.StorageService.Backup
1088     * @systemapi
1089     * @since 20
1090     */
1091    cleanBundleTempDir(bundleName: string): Promise<boolean>;
1092
1093    /**
1094     * Provides an interface for the tool to get compatibility info.
1095     * @permission ohos.permission.BACKUP
1096     * @param { string } bundleName - Set the bundleName of the application that need to get compatibilityInfo.
1097     * @param { string } extInfo - Indicates the extension information of application.
1098     * @returns { Promise<string> } Return compatibility info.
1099     * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken.
1100     * @throws { BusinessError } 202 - Permission verification failed,
1101     *     application which is not a system application uses system API.
1102     * @syscap SystemCapability.FileManagement.StorageService.Backup
1103     * @systemapi
1104     * @since 20
1105     */
1106    getCompatibilityInfo(bundleName: string, extInfo: string): Promise<string>;
1107  }
1108}
1109export default backup;
1110