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 /** 668 * Control class for restore procedure. 669 * 670 * @syscap SystemCapability.FileManagement.StorageService.Backup 671 * @systemapi 672 * @since 10 673 */ 674 class SessionRestore { 675 /** 676 * Constructor for obtaining the instance of the SessionBackup class. 677 * 678 * @permission ohos.permission.BACKUP 679 * @param { GeneralCallbacks } callbacks Callbacks to be registered for the restore. 680 * @syscap SystemCapability.FileManagement.StorageService.Backup 681 * @systemapi 682 * @since 10 683 */ 684 constructor(callbacks: GeneralCallbacks); 685 686 /** 687 * Obtain a Json file that describes local capabilities. 688 * 689 * @permission ohos.permission.BACKUP 690 * @returns { Promise<FileData> } A FileData holding all the local capabilities. The returned file is a temporal file that will be 691 * deleted automatically when closed. 692 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 693 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 694 * @throws { BusinessError } 13600001 - IPC error 695 * @throws { BusinessError } 13900001 - Operation not permitted 696 * @throws { BusinessError } 13900020 - Invalid argument 697 * @throws { BusinessError } 13900042 - Internal error 698 * @syscap SystemCapability.FileManagement.StorageService.Backup 699 * @systemapi 700 * @since 18 701 */ 702 getLocalCapabilities(): Promise<FileData>; 703 704 /** 705 * Append new bundles to be restore up during the restore. 706 * 707 * @permission ohos.permission.BACKUP 708 * @param { number } remoteCapabilitiesFd Opened JSON file that stores remote device capabilities. 709 * You can use the getLocalCapabilities method to obtain the value. 710 * @param { string[] } bundlesToBackup Bundles to restore. 711 * @returns { Promise<void> } The promise returned by the function. 712 * @throws { BusinessError } 13600001 - IPC error 713 * @throws { BusinessError } 13900001 - Operation not permitted 714 * @throws { BusinessError } 13900005 - I/O error 715 * @throws { BusinessError } 13900011 - Out of memory 716 * @throws { BusinessError } 13900020 - Invalid argument 717 * @throws { BusinessError } 13900025 - No space left on device 718 * @throws { BusinessError } 13900042 - Unknown error 719 * @syscap SystemCapability.FileManagement.StorageService.Backup 720 * @systemapi 721 * @since 10 722 */ 723 /** 724 * Append new bundles and restoreInfos to be restore up during the restore. 725 * 726 * @permission ohos.permission.BACKUP 727 * @param { number } remoteCapabilitiesFd Opened JSON file that stores remote device capabilities. 728 * You can use the getLocalCapabilities method to obtain the value. 729 * @param { string[] } bundlesToBackup Bundles to restore. 730 * @param { string[] } [infos] infos to restore 731 * @returns { Promise<void> } The promise returned by the function. 732 * @throws { BusinessError } 13600001 - IPC error 733 * @throws { BusinessError } 13900001 - Operation not permitted 734 * @throws { BusinessError } 13900005 - I/O error 735 * @throws { BusinessError } 13900011 - Out of memory 736 * @throws { BusinessError } 13900020 - Invalid argument 737 * @throws { BusinessError } 13900025 - No space left on device 738 * @throws { BusinessError } 13900042 - Unknown error 739 * @syscap SystemCapability.FileManagement.StorageService.Backup 740 * @systemapi 741 * @since 12 742 */ 743 appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], infos?: string[]): Promise<void>; 744 745 /** 746 * Append new bundles to be restore up during the restore. 747 * 748 * @permission ohos.permission.BACKUP 749 * @param { number } remoteCapabilitiesFd Opened JSON file that stores remote device capabilities. 750 * You can use the getLocalCapabilities method to obtain the value. 751 * @param { string[] } bundlesToBackup Bundles to restore. 752 * @param { AsyncCallback<void> } callback Asynchronous callback to be called when appendBundles has finished. 753 * @throws { BusinessError } 13600001 - IPC error 754 * @throws { BusinessError } 13900001 - Operation not permitted 755 * @throws { BusinessError } 13900005 - I/O error 756 * @throws { BusinessError } 13900011 - Out of memory 757 * @throws { BusinessError } 13900020 - Invalid argument 758 * @throws { BusinessError } 13900025 - No space left on device 759 * @throws { BusinessError } 13900042 - Unknown error 760 * @syscap SystemCapability.FileManagement.StorageService.Backup 761 * @systemapi 762 * @since 10 763 */ 764 appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback: AsyncCallback<void>): void; 765 766 /** 767 * Publish the file handle to the backup service to make the service aware that the file's content is ready. 768 * This interface is part of the zero-copy feature. 769 * 770 * @permission ohos.permission.BACKUP 771 * @param { FileMeta } fileMeta Metadata of the file to be sent. Make sure that the backup framework holds 772 * this file by calling getFileHandle. 773 * @returns { Promise<void> } The promise returned by the function. 774 * @throws { BusinessError } 13600001 - IPC error 775 * @throws { BusinessError } 13900001 - Operation not permitted 776 * @throws { BusinessError } 13900020 - Invalid argument 777 * @throws { BusinessError } 13900042 - Unknown error 778 * @syscap SystemCapability.FileManagement.StorageService.Backup 779 * @systemapi 780 * @since 10 781 */ 782 publishFile(fileMeta: FileMeta): Promise<void>; 783 784 /** 785 * Publish the file handle to the backup service to make the service aware that the file's content is ready. 786 * This interface is part of the zero-copy feature. 787 * 788 * @permission ohos.permission.BACKUP 789 * @param { FileMeta } fileMeta Metadata of the file to be sent. Make sure that the backup framework holds 790 * this file by calling getFileHandle. 791 * @param { AsyncCallback<void> } callback Asynchronous callback to be called when publishFile has finished. 792 * @throws { BusinessError } 13600001 - IPC error 793 * @throws { BusinessError } 13900001 - Operation not permitted 794 * @throws { BusinessError } 13900020 - Invalid argument 795 * @throws { BusinessError } 13900042 - Unknown error 796 * @syscap SystemCapability.FileManagement.StorageService.Backup 797 * @systemapi 798 * @since 10 799 */ 800 publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void; 801 802 /** 803 * Request to get a shared file from the service. This interface is part of the zero-copy feature. 804 * Developers could get the file through onFileReady callback. 805 * When the client accomplished the file, use publishFile to publish. 806 * 807 * @permission ohos.permission.BACKUP 808 * @param { FileMeta } fileMeta Metadata of the file to be sent. Note that all the files should come 809 * from the backup procedure or the getLocalCapabilities method. 810 * @returns { Promise<void> } The promise returned by the function. 811 * @throws { BusinessError } 13600001 - IPC error 812 * @throws { BusinessError } 13900001 - Operation not permitted 813 * @throws { BusinessError } 13900020 - Invalid argument 814 * @throws { BusinessError } 13900042 - Unknown error 815 * @syscap SystemCapability.FileManagement.StorageService.Backup 816 * @systemapi 817 * @since 10 818 */ 819 getFileHandle(fileMeta: FileMeta): Promise<void>; 820 821 /** 822 * Request to get a shared file from the service. This interface is part of the zero-copy feature. 823 * Developers could get the file through onFileReady callback. 824 * When the client accomplished the file, use publishFile to publish. 825 * 826 * @permission ohos.permission.BACKUP 827 * @param { FileMeta } fileMeta Metadata of the file to be sent. Note that all the files should come 828 * from the backup procedure or the getLocalCapabilities method. 829 * @param { AsyncCallback<void> } callback Asynchronous callback to be called when getFileHandle has finished. 830 * @throws { BusinessError } 13600001 - IPC error 831 * @throws { BusinessError } 13900001 - Operation not permitted 832 * @throws { BusinessError } 13900020 - Invalid argument 833 * @throws { BusinessError } 13900042 - Unknown error 834 * @syscap SystemCapability.FileManagement.StorageService.Backup 835 * @systemapi 836 * @since 10 837 */ 838 getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void; 839 840 /** 841 * End restore process 842 * 843 * @permission ohos.permission.BACKUP 844 * @returns { Promise<void> } The promise returned by the function. 845 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 846 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 847 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 848 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 849 * @throws { BusinessError } 13600001 - IPC error 850 * @throws { BusinessError } 13900001 - Operation not permitted 851 * @throws { BusinessError } 13900005 - I/O error 852 * @throws { BusinessError } 13900042 - Unknown error 853 * @syscap SystemCapability.FileManagement.StorageService.Backup 854 * @systemapi 855 * @since 12 856 */ 857 release(): Promise<void>; 858 859 /** 860 * cancel the application being restore. 861 * 862 * @permission ohos.permission.BACKUP 863 * @param { string } bundleName - Set the bundleName of the application to be canceled. 864 * @returns { number } Return cancel result, 0 is success, 13500011 is fail, 13500012 is not have task. 865 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 866 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 867 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 868 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 869 * @syscap SystemCapability.FileManagement.StorageService.Backup 870 * @systemapi 871 * @since 18 872 */ 873 cancel(bundleName: string): number; 874 } 875 876 /** 877 * Control class for incremental backup procedure. 878 * 879 * @syscap SystemCapability.FileManagement.StorageService.Backup 880 * @systemapi 881 * @since 12 882 */ 883 class IncrementalBackupSession { 884 /** 885 * Constructor for obtaining the instance of the IncrementalBackupSession class. 886 * 887 * @permission ohos.permission.BACKUP 888 * @param { GeneralCallbacks } callbacks Callbacks to be registered for the backup. 889 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 890 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 891 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 892 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 893 * @syscap SystemCapability.FileManagement.StorageService.Backup 894 * @systemapi 895 * @since 12 896 */ 897 constructor(callbacks: GeneralCallbacks); 898 899 /** 900 * Obtain a Json file that describes local capabilities. 901 * 902 * @permission ohos.permission.BACKUP 903 * @returns { Promise<FileData> } A FileData holding all the local capabilities. The returned file is a temporal file that will be 904 * deleted automatically when closed. 905 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 906 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 907 * @throws { BusinessError } 13600001 - IPC error 908 * @throws { BusinessError } 13900001 - Operation not permitted 909 * @throws { BusinessError } 13900020 - Invalid argument 910 * @throws { BusinessError } 13900042 - Internal error 911 * @syscap SystemCapability.FileManagement.StorageService.Backup 912 * @systemapi 913 * @since 18 914 */ 915 getLocalCapabilities(): Promise<FileData>; 916 917 /** 918 * Obtain application data size to be backed up. 919 * 920 * @permission ohos.permission.BACKUP 921 * @param { boolean } isPreciseScan Indicates whether to obtain the exact data size. 922 * @param { Array<IncrementalBackupTime> } dataList Application list. 923 * @returns { Promise<void> } The promise returned by the function. 924 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 925 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 926 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 927 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 928 * @throws { BusinessError } 13600001 - IPC error 929 * @throws { BusinessError } 13900001 - Operation not permitted 930 * @throws { BusinessError } 13900020 - Invalid argument 931 * @throws { BusinessError } 13900042 - Internal error 932 * @syscap SystemCapability.FileManagement.StorageService.Backup 933 * @systemapi 934 * @since 18 935 */ 936 getBackupDataSize(isPreciseScan: boolean, dataList: Array<IncrementalBackupTime>): Promise<void>; 937 938 /** 939 * Append new bundles to incremental backup. 940 * 941 * @permission ohos.permission.BACKUP 942 * @param { Array<IncrementalBackupData> } bundlesToBackup Bundles to incremental backup. 943 * @returns { Promise<void> } The promise returned by the function. 944 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 945 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 946 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 947 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 948 * @throws { BusinessError } 13600001 - IPC error 949 * @throws { BusinessError } 13900001 - Operation not permitted 950 * @throws { BusinessError } 13900005 - I/O error 951 * @throws { BusinessError } 13900011 - Out of memory 952 * @throws { BusinessError } 13900025 - No space left on device 953 * @throws { BusinessError } 13900042 - Unknown error 954 * @syscap SystemCapability.FileManagement.StorageService.Backup 955 * @systemapi 956 * @since 12 957 */ 958 appendBundles(bundlesToBackup: Array<IncrementalBackupData>): Promise<void>; 959 960 /** 961 * Append new bundles to incremental backup. 962 * 963 * @permission ohos.permission.BACKUP 964 * @param { Array<IncrementalBackupData> } bundlesToAppend Bundles to incremental backup. 965 * @param { string[] } infos information of the bundlesToBackup 966 * @returns { Promise<void> } The promise returned by the function. 967 * @throws { BusinessError } 201 - Permission verification failed. This error code is usually the result returned by VerifyAccessToken. 968 * @throws { BusinessError } 202 - Permission verification failed. A non-system application calls a system API. 969 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 970 * <br>2. Incorrect parameter types. 3. Parameter verification failed. 971 * @throws { BusinessError } 13600001 - IPC error 972 * @throws { BusinessError } 13900001 - Operation not permitted 973 * @throws { BusinessError } 13900005 - I/O error 974 * @throws { BusinessError } 13900011 - Out of memory 975 * @throws { BusinessError } 13900025 - No space left on device 976 * @throws { BusinessError } 13900042 - Unknown error 977 * @syscap SystemCapability.FileManagement.StorageService.Backup 978 * @systemapi 979 * @since 12 980 */ 981 appendBundles(bundlesToAppend: Array<IncrementalBackupData>, infos: string[]): Promise<void>; 982 983 /** 984 * End backup process 985 * 986 * @permission ohos.permission.BACKUP 987 * @returns { Promise<void> } The promise returned by the function. 988 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 989 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 990 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 991 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 992 * @throws { BusinessError } 13600001 - IPC error 993 * @throws { BusinessError } 13900001 - Operation not permitted 994 * @throws { BusinessError } 13900005 - I/O error 995 * @throws { BusinessError } 13900042 - Unknown error 996 * @syscap SystemCapability.FileManagement.StorageService.Backup 997 * @systemapi 998 * @since 12 999 */ 1000 release(): Promise<void>; 1001 1002 /** 1003 * cancel the application being incrementalBackup. 1004 * 1005 * @permission ohos.permission.BACKUP 1006 * @param { string } bundleName - Set the bundleName of the application to be canceled. 1007 * @returns { number } Return cancel result, 0 is success, 13500011 is fail, 13500012 is not have task. 1008 * @throws { BusinessError } 201 - Permission verification failed, usually the result returned by VerifyAccessToken. 1009 * @throws { BusinessError } 202 - Permission verification failed, application which is not a system application uses system API. 1010 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 1011 * <br>2. Incorrect parameter types. 3.Parameter verification failed. 1012 * @syscap SystemCapability.FileManagement.StorageService.Backup 1013 * @systemapi 1014 * @since 18 1015 */ 1016 cancel(bundleName: string): number; 1017 } 1018} 1019export default backup; 1020