Home | History | Annotate | Download | only in backup
      1 /*
      2  * Copyright (C) 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.backup;
     18 
     19 import android.app.backup.IFullBackupRestoreObserver;
     20 import android.app.backup.IRestoreSession;
     21 import android.os.ParcelFileDescriptor;
     22 import android.content.Intent;
     23 
     24 /**
     25  * Direct interface to the Backup Manager Service that applications invoke on.  The only
     26  * operation currently needed is a simple notification that the app has made changes to
     27  * data it wishes to back up, so the system should run a backup pass.
     28  *
     29  * Apps will use the {@link android.app.backup.BackupManager} class rather than going through
     30  * this Binder interface directly.
     31  *
     32  * {@hide}
     33  */
     34 interface IBackupManager {
     35     /**
     36      * Tell the system service that the caller has made changes to its
     37      * data, and therefore needs to undergo an incremental backup pass.
     38      *
     39      * Any application can invoke this method for its own package, but
     40      * only callers who hold the android.permission.BACKUP permission
     41      * may invoke it for arbitrary packages.
     42      */
     43     void dataChanged(String packageName);
     44 
     45     /**
     46      * Erase all backed-up data for the given package from the given storage
     47      * destination.
     48      *
     49      * Any application can invoke this method for its own package, but
     50      * only callers who hold the android.permission.BACKUP permission
     51      * may invoke it for arbitrary packages.
     52      */
     53     void clearBackupData(String transportName, String packageName);
     54 
     55     /**
     56      * Notifies the Backup Manager Service that an agent has become available.  This
     57      * method is only invoked by the Activity Manager.
     58      */
     59     void agentConnected(String packageName, IBinder agent);
     60 
     61     /**
     62      * Notify the Backup Manager Service that an agent has unexpectedly gone away.
     63      * This method is only invoked by the Activity Manager.
     64      */
     65     void agentDisconnected(String packageName);
     66 
     67     /**
     68      * Notify the Backup Manager Service that an application being installed will
     69      * need a data-restore pass.  This method is only invoked by the Package Manager.
     70      */
     71     void restoreAtInstall(String packageName, int token);
     72 
     73     /**
     74      * Enable/disable the backup service entirely.  When disabled, no backup
     75      * or restore operations will take place.  Data-changed notifications will
     76      * still be observed and collected, however, so that changes made while the
     77      * mechanism was disabled will still be backed up properly if it is enabled
     78      * at some point in the future.
     79      *
     80      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
     81      */
     82     void setBackupEnabled(boolean isEnabled);
     83 
     84     /**
     85      * Enable/disable automatic restore of application data at install time.  When
     86      * enabled, installation of any package will involve the Backup Manager.  If data
     87      * exists for the newly-installed package, either from the device's current [enabled]
     88      * backup dataset or from the restore set used in the last wholesale restore operation,
     89      * that data will be supplied to the new package's restore agent before the package
     90      * is made generally available for launch.
     91      *
     92      * <p>Callers must hold  the android.permission.BACKUP permission to use this method.
     93      *
     94      * @param doAutoRestore When true, enables the automatic app-data restore facility.  When
     95      *   false, this facility will be disabled.
     96      */
     97     void setAutoRestore(boolean doAutoRestore);
     98 
     99     /**
    100      * Indicate that any necessary one-time provisioning has occurred.
    101      *
    102      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
    103      */
    104     void setBackupProvisioned(boolean isProvisioned);
    105 
    106     /**
    107      * Report whether the backup mechanism is currently enabled.
    108      *
    109      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
    110      */
    111     boolean isBackupEnabled();
    112 
    113     /**
    114      * Set the device's backup password.  Returns {@code true} if the password was set
    115      * successfully, {@code false} otherwise.  Typically a failure means that an incorrect
    116      * current password was supplied.
    117      *
    118      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
    119      */
    120     boolean setBackupPassword(in String currentPw, in String newPw);
    121 
    122     /**
    123      * Reports whether a backup password is currently set.  If not, then a null or empty
    124      * "current password" argument should be passed to setBackupPassword().
    125      *
    126      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
    127      */
    128     boolean hasBackupPassword();
    129 
    130     /**
    131      * Schedule an immediate backup attempt for all pending updates.  This is
    132      * primarily intended for transports to use when they detect a suitable
    133      * opportunity for doing a backup pass.  If there are no pending updates to
    134      * be sent, no action will be taken.  Even if some updates are pending, the
    135      * transport will still be asked to confirm via the usual requestBackupTime()
    136      * method.
    137      *
    138      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
    139      */
    140     void backupNow();
    141 
    142     /**
    143      * Write a full backup of the given package to the supplied file descriptor.
    144      * The fd may be a socket or other non-seekable destination.  If no package names
    145      * are supplied, then every application on the device will be backed up to the output.
    146      *
    147      * <p>This method is <i>synchronous</i> -- it does not return until the backup has
    148      * completed.
    149      *
    150      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
    151      *
    152      * @param fd The file descriptor to which a 'tar' file stream is to be written
    153      * @param includeApks If <code>true</code>, the resulting tar stream will include the
    154      *     application .apk files themselves as well as their data.
    155      * @param includeObbs If <code>true</code>, the resulting tar stream will include any
    156      *     application expansion (OBB) files themselves belonging to each application.
    157      * @param includeShared If <code>true</code>, the resulting tar stream will include
    158      *     the contents of the device's shared storage (SD card or equivalent).
    159      * @param allApps If <code>true</code>, the resulting tar stream will include all
    160      *     installed applications' data, not just those named in the <code>packageNames</code>
    161      *     parameter.
    162      * @param allIncludesSystem If {@code true}, then {@code allApps} will be interpreted
    163      *     as including packages pre-installed as part of the system. If {@code false},
    164      *     then setting {@code allApps} to {@code true} will mean only that all 3rd-party
    165      *     applications will be included in the dataset.
    166      * @param packageNames The package names of the apps whose data (and optionally .apk files)
    167      *     are to be backed up.  The <code>allApps</code> parameter supersedes this.
    168      */
    169     void fullBackup(in ParcelFileDescriptor fd, boolean includeApks, boolean includeObbs,
    170             boolean includeShared, boolean doWidgets, boolean allApps, boolean allIncludesSystem,
    171             boolean doCompress, in String[] packageNames);
    172 
    173     /**
    174      * Perform a full-dataset backup of the given applications via the currently active
    175      * transport.
    176      *
    177      * @param packageNames The package names of the apps whose data are to be backed up.
    178      */
    179     void fullTransportBackup(in String[] packageNames);
    180 
    181     /**
    182      * Restore device content from the data stream passed through the given socket.  The
    183      * data stream must be in the format emitted by fullBackup().
    184      *
    185      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
    186      */
    187     void fullRestore(in ParcelFileDescriptor fd);
    188 
    189     /**
    190      * Confirm that the requested full backup/restore operation can proceed.  The system will
    191      * not actually perform the operation described to fullBackup() / fullRestore() unless the
    192      * UI calls back into the Backup Manager to confirm, passing the correct token.  At
    193      * the same time, the UI supplies a callback Binder for progress notifications during
    194      * the operation.
    195      *
    196      * <p>The password passed by the confirming entity must match the saved backup or
    197      * full-device encryption password in order to perform a backup.  If a password is
    198      * supplied for restore, it must match the password used when creating the full
    199      * backup dataset being used for restore.
    200      *
    201      * <p>Callers must hold the android.permission.BACKUP permission to use this method.
    202      */
    203     void acknowledgeFullBackupOrRestore(int token, boolean allow,
    204             in String curPassword, in String encryptionPassword,
    205             IFullBackupRestoreObserver observer);
    206 
    207     /**
    208      * Identify the currently selected transport.  Callers must hold the
    209      * android.permission.BACKUP permission to use this method.
    210      */
    211     String getCurrentTransport();
    212 
    213     /**
    214      * Request a list of all available backup transports' names.  Callers must
    215      * hold the android.permission.BACKUP permission to use this method.
    216      */
    217     String[] listAllTransports();
    218 
    219     /**
    220      * Specify the current backup transport.  Callers must hold the
    221      * android.permission.BACKUP permission to use this method.
    222      *
    223      * @param transport The name of the transport to select.  This should be one
    224      * of {@link BackupManager.TRANSPORT_GOOGLE} or {@link BackupManager.TRANSPORT_ADB}.
    225      * @return The name of the previously selected transport.  If the given transport
    226      *   name is not one of the currently available transports, no change is made to
    227      *   the current transport setting and the method returns null.
    228      */
    229     String selectBackupTransport(String transport);
    230 
    231     /**
    232      * Get the configuration Intent, if any, from the given transport.  Callers must
    233      * hold the android.permission.BACKUP permission in order to use this method.
    234      *
    235      * @param transport The name of the transport to query.
    236      * @return An Intent to use with Activity#startActivity() to bring up the configuration
    237      *   UI supplied by the transport.  If the transport has no configuration UI, it should
    238      *   return {@code null} here.
    239      */
    240     Intent getConfigurationIntent(String transport);
    241 
    242     /**
    243      * Get the destination string supplied by the given transport.  Callers must
    244      * hold the android.permission.BACKUP permission in order to use this method.
    245      *
    246      * @param transport The name of the transport to query.
    247      * @return A string describing the current backup destination.  This string is used
    248      *   verbatim by the Settings UI as the summary text of the "configure..." item.
    249      */
    250     String getDestinationString(String transport);
    251 
    252     /**
    253      * Get the manage-data UI intent, if any, from the given transport.  Callers must
    254      * hold the android.permission.BACKUP permission in order to use this method.
    255      */
    256     Intent getDataManagementIntent(String transport);
    257 
    258     /**
    259      * Get the manage-data menu label, if any, from the given transport.  Callers must
    260      * hold the android.permission.BACKUP permission in order to use this method.
    261      */
    262     String getDataManagementLabel(String transport);
    263 
    264     /**
    265      * Begin a restore session.  Either or both of packageName and transportID
    266      * may be null.  If packageName is non-null, then only the given package will be
    267      * considered for restore.  If transportID is null, then the restore will use
    268      * the current active transport.
    269      * <p>
    270      * This method requires the android.permission.BACKUP permission <i>except</i>
    271      * when transportID is null and packageName is the name of the caller's own
    272      * package.  In that case, the restore session returned is suitable for supporting
    273      * the BackupManager.requestRestore() functionality via RestoreSession.restorePackage()
    274      * without requiring the app to hold any special permission.
    275      *
    276      * @param packageName The name of the single package for which a restore will
    277      *        be requested.  May be null, in which case all packages in the restore
    278      *        set can be restored.
    279      * @param transportID The name of the transport to use for the restore operation.
    280      *        May be null, in which case the current active transport is used.
    281      * @return An interface to the restore session, or null on error.
    282      */
    283     IRestoreSession beginRestoreSession(String packageName, String transportID);
    284 
    285     /**
    286      * Notify the backup manager that a BackupAgent has completed the operation
    287      * corresponding to the given token.
    288      *
    289      * @param token The transaction token passed to a BackupAgent's doBackup() or
    290      *        doRestore() method.
    291      * {@hide}
    292      */
    293     void opComplete(int token);
    294 }
    295