Home | History | Annotate | Download | only in app
      1 /*
      2  * Copyright 2009, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.app;
     18 
     19 import android.app.backup.IBackupManager;
     20 import android.os.ParcelFileDescriptor;
     21 
     22 /**
     23  * Interface presented by applications being asked to participate in the
     24  * backup & restore mechanism.  End user code will not typically implement
     25  * this interface directly; they subclass BackupAgent instead.
     26  *
     27  * {@hide}
     28  */
     29 oneway interface IBackupAgent {
     30     /**
     31      * Request that the app perform an incremental backup.
     32      *
     33      * @param oldState Read-only file containing the description blob of the
     34      *        app's data state as of the last backup operation's completion.
     35      *        This file is empty or invalid when a full backup is being
     36      *        requested.
     37      *
     38      * @param data Read-write file, empty when onBackup() is called, that
     39      *        is the data destination for this backup pass's incrementals.
     40      *
     41      * @param newState Read-write file, empty when onBackup() is called,
     42      *        where the new state blob is to be recorded.
     43      *
     44      * @param quota Quota reported by the transport for this backup operation (in bytes).
     45      *
     46      * @param token Opaque token identifying this transaction.  This must
     47      *        be echoed back to the backup service binder once the new
     48      *        data has been written to the data and newState files.
     49      *
     50      * @param callbackBinder Binder on which to indicate operation completion,
     51      *        passed here as a convenience to the agent.
     52      *
     53      * @param transportFlags Flags with additional information about the transport.
     54      */
     55     void doBackup(in ParcelFileDescriptor oldState,
     56             in ParcelFileDescriptor data,
     57             in ParcelFileDescriptor newState,
     58             long quotaBytes, int token, IBackupManager callbackBinder, int transportFlags);
     59 
     60     /**
     61      * Restore an entire data snapshot to the application.
     62      *
     63      * @param data Read-only file containing the full data snapshot of the
     64      *        app's backup.  This is to be a <i>replacement</i> of the app's
     65      *        current data, not to be merged into it.
     66      *
     67      * @param appVersionCode The android:versionCode attribute of the application
     68      *        that created this data set.  This can help the agent distinguish among
     69      *        various historical backup content possibilities.
     70      *
     71      * @param newState Read-write file, empty when onRestore() is called,
     72      *        that is to be written with the state description that holds after
     73      *        the restore has been completed.
     74      *
     75      * @param token Opaque token identifying this transaction.  This must
     76      *        be echoed back to the backup service binder once the agent is
     77      *        finished restoring the application based on the restore data
     78      *        contents.
     79      *
     80      * @param callbackBinder Binder on which to indicate operation completion,
     81      *        passed here as a convenience to the agent.
     82      */
     83     void doRestore(in ParcelFileDescriptor data,
     84             long appVersionCode, in ParcelFileDescriptor newState,
     85             int token, IBackupManager callbackBinder);
     86 
     87     /**
     88      * Perform a "full" backup to the given file descriptor.  The output file is presumed
     89      * to be a socket or other non-seekable, write-only data sink.  When this method is
     90      * called, the app should write all of its files to the output.
     91      *
     92      * @param data Write-only file to receive the backed-up file content stream.
     93      *        The data must be formatted correctly for the resulting archive to be
     94      *        legitimate, so that will be tightly controlled by the available API.
     95      *
     96      * @param quota Quota reported by the transport for this backup operation (in bytes).
     97      *
     98      * @param token Opaque token identifying this transaction.  This must
     99      *        be echoed back to the backup service binder once the agent is
    100      *        finished restoring the application based on the restore data
    101      *        contents.
    102      *
    103      * @param callbackBinder Binder on which to indicate operation completion,
    104      *        passed here as a convenience to the agent.
    105      *
    106      * @param transportFlags Flags with additional information about transport.
    107      */
    108     void doFullBackup(in ParcelFileDescriptor data, long quotaBytes, int token,
    109             IBackupManager callbackBinder, int transportFlags);
    110 
    111     /**
    112      * Estimate how much data a full backup will deliver
    113      */
    114     void doMeasureFullBackup(long quotaBytes, int token, IBackupManager callbackBinder,
    115             int transportFlags);
    116 
    117     /**
    118      * Tells the application agent that the backup data size exceeded current transport quota.
    119      * Later calls to {@link #onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}
    120      * and {@link #onFullBackup(FullBackupDataOutput)} could use this information
    121      * to reduce backup size under the limit.
    122      * However, the quota can change, so do not assume that the value passed in here is absolute,
    123      * similarly all subsequent backups should not be restricted to this size.
    124      * This callback will be invoked before data has been put onto the wire in a preflight check,
    125      * so it is relatively inexpensive to hit your quota.
    126      * Apps that hit quota repeatedly without dealing with it can be subject to having their backup
    127      * schedule reduced.
    128      * The {@code quotaBytes} is a loose guideline b/c of metadata added by the backupmanager
    129      * so apps should be more aggressive in trimming their backup set.
    130      *
    131      * @param backupDataBytes Expected or already processed amount of data.
    132      *                        Could be less than total backup size if backup process was interrupted
    133      *                        before finish of processing all backup data.
    134      * @param quotaBytes Current amount of backup data that is allowed for the app.
    135      */
    136     void doQuotaExceeded(long backupDataBytes, long quotaBytes);
    137 
    138     /**
    139      * Restore a single "file" to the application.  The file was typically obtained from
    140      * a full-backup dataset.  The agent reads 'size' bytes of file content
    141      * from the provided file descriptor.
    142      *
    143      * @param data Read-only pipe delivering the file content itself.
    144      *
    145      * @param size Size of the file being restored.
    146      * @param type Type of file system entity, e.g. FullBackup.TYPE_DIRECTORY.
    147      * @param domain Name of the file's semantic domain to which the 'path' argument is a
    148      *        relative path.  e.g. FullBackup.DATABASE_TREE_TOKEN.
    149      * @param path Relative path of the file within its semantic domain.
    150      * @param mode Access mode of the file system entity, e.g. 0660.
    151      * @param mtime Last modification time of the file system entity.
    152      * @param token Opaque token identifying this transaction.  This must
    153      *        be echoed back to the backup service binder once the agent is
    154      *        finished restoring the application based on the restore data
    155      *        contents.
    156      * @param callbackBinder Binder on which to indicate operation completion,
    157      *        passed here as a convenience to the agent.
    158      */
    159     void doRestoreFile(in ParcelFileDescriptor data, long size,
    160             int type, String domain, String path, long mode, long mtime,
    161             int token, IBackupManager callbackBinder);
    162 
    163     /**
    164      * Provide the app with a canonical "all data has been delivered" end-of-restore
    165      * callback so that it can do any postprocessing of the restored data that might
    166      * be appropriate.  This is issued after both key/value and full data restore
    167      * operations have completed.
    168      *
    169      * @param token Opaque token identifying this transaction.  This must
    170      *        be echoed back to the backup service binder once the agent is
    171      *        finished restoring the application based on the restore data
    172      *        contents.
    173      * @param callbackBinder Binder on which to indicate operation completion,
    174      *        passed here as a convenience to the agent.
    175      */
    176     void doRestoreFinished(int token, IBackupManager callbackBinder);
    177 
    178     /**
    179      * Out of band: instruct the agent to crash within the client process.  This is used
    180      * when the backup infrastructure detects a semantic error post-hoc and needs to
    181      * pass the problem back to the app.
    182      *
    183      * @param message The message to be passed to the agent's application in an exception.
    184      */
    185     void fail(String message);
    186 }
    187