blob: 4bef265cc3e9a68b4dd44b4a9aa3285e477eb9d7 [file] [log] [blame]
Christopher Tate487529a2009-04-29 14:03:25 -07001/*
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
17package com.android.internal.backup;
18
Christopher Tate9b3905c2009-06-08 15:24:01 -070019import android.backup.RestoreSet;
Christopher Tate7b881282009-06-07 13:52:37 -070020import android.content.pm.PackageInfo;
Christopher Tatee10be802009-05-07 17:22:16 -070021import android.os.ParcelFileDescriptor;
22
Christopher Tate487529a2009-04-29 14:03:25 -070023/** {@hide} */
24interface IBackupTransport {
Christopher Tatee10be802009-05-07 17:22:16 -070025/* STOPSHIP - don't ship with this comment in place
26 Things the transport interface has to do:
27 1. set up the connection to the destination
28 - set up encryption
29 - for Google cloud, log in using the user's gaia credential or whatever
Christopher Tate7b881282009-06-07 13:52:37 -070030 - for adb, just set up the all-in-one destination file
Christopher Tatee10be802009-05-07 17:22:16 -070031 2. send each app's backup transaction
32 - parse the data file for key/value pointers etc
33 - send key/blobsize set to the Google cloud, get back quota ok/rejected response
34 - sd/adb doesn't preflight; no per-app quota
35 - app's entire change is essentially atomic
36 - cloud transaction encrypts then sends each key/value pair separately; we already
37 parsed the data when preflighting so we don't have to again here
38 - sd target streams raw data into encryption envelope then to sd?
39 3. shut down connection to destination
40 - cloud: tear down connection etc
Christopher Tate7b881282009-06-07 13:52:37 -070041 - adb: close the file
Christopher Tatee10be802009-05-07 17:22:16 -070042*/
43 /**
Christopher Tate5cb400b2009-06-25 16:03:14 -070044 * Ask the transport where, on local device storage, to keep backup state blobs.
45 * This is per-transport so that mock transports used for testing can coexist with
46 * "live" backup services without interfering with the live bookkeeping. The
47 * returned string should be a name that is expected to be unambiguous among all
48 * available backup transports; the name of the class implementing the transport
49 * is a good choice.
50 *
51 * @return A unique name, suitable for use as a file or directory name, that the
52 * Backup Manager could use to disambiguate state files associated with
53 * different backup transports.
54 */
55 String transportDirName();
56
57 /**
Christopher Tatedf01dea2009-06-09 20:45:02 -070058 * Verify that this is a suitable time for a backup pass. This should return zero
Christopher Tateaa088442009-06-16 18:25:46 -070059 * if a backup is reasonable right now, some positive value otherwise. This method
60 * will be called outside of the {@link #startSession}/{@link #endSession} pair.
Christopher Tatedf01dea2009-06-09 20:45:02 -070061 *
Christopher Tateaa088442009-06-16 18:25:46 -070062 * <p>If this is not a suitable time for a backup, the transport should return a
Christopher Tatedf01dea2009-06-09 20:45:02 -070063 * backoff delay, in milliseconds, after which the Backup Manager should try again.
Christopher Tateaa088442009-06-16 18:25:46 -070064 *
65 * @return Zero if this is a suitable time for a backup pass, or a positive time delay
66 * in milliseconds to suggest deferring the backup pass for a while.
Christopher Tatedf01dea2009-06-09 20:45:02 -070067 */
68 long requestBackupTime();
69
70 /**
Dan Egnorefe52642009-06-24 00:16:33 -070071 * Send one application's data to the backup destination. The transport may send
72 * the data immediately, or may buffer it. After this is called, {@link #finishBackup}
73 * must be called to ensure the data is sent and recorded successfully.
Christopher Tatee10be802009-05-07 17:22:16 -070074 *
Christopher Tateb4a61882009-06-07 15:19:32 -070075 * @param packageInfo The identity of the application whose data is being backed up.
76 * This specifically includes the signature list for the package.
Christopher Tatee10be802009-05-07 17:22:16 -070077 * @param data The data stream that resulted from invoking the application's
Christopher Tate7b881282009-06-07 13:52:37 -070078 * BackupService.doBackup() method. This may be a pipe rather than a file on
79 * persistent media, so it may not be seekable.
Dan Egnorefe52642009-06-24 00:16:33 -070080 * @return false if errors occurred (the backup should be aborted and rescheduled),
81 * true if everything is OK so far (but {@link #finishBackup} must be called).
Christopher Tatee10be802009-05-07 17:22:16 -070082 */
Dan Egnorefe52642009-06-24 00:16:33 -070083 boolean performBackup(in PackageInfo packageInfo, in ParcelFileDescriptor inFd);
84
85 /**
86 * Finish sending application data to the backup destination. This must be
87 * called after {@link #performBackup} to ensure that all data is sent. Only
88 * when this method returns true can the backup be assumed to have succeeded.
89 *
90 * @return false if errors occurred (the backup should be aborted and rescheduled),
91 * true if everything is OK so far (but {@link #finishBackup} must be called).
92 */
93 boolean finishBackup();
Christopher Tatee10be802009-05-07 17:22:16 -070094
95 /**
Christopher Tateb4a61882009-06-07 15:19:32 -070096 * Get the set of backups currently available over this transport.
97 *
Dan Egnorefe52642009-06-24 00:16:33 -070098 * @return Descriptions of the set of restore images available for this device,
99 * or null if an error occurred (the attempt should be rescheduled).
Christopher Tateb4a61882009-06-07 15:19:32 -0700100 **/
Christopher Tate9b3905c2009-06-08 15:24:01 -0700101 RestoreSet[] getAvailableRestoreSets();
Christopher Tateb4a61882009-06-07 15:19:32 -0700102
103 /**
Dan Egnorefe52642009-06-24 00:16:33 -0700104 * Start restoring application data from backup. After calling this function,
105 * alternate calls to {@link #nextRestorePackage} and {@link #nextRestoreData}
106 * to walk through the actual application data.
Christopher Tateb4a61882009-06-07 15:19:32 -0700107 *
Christopher Tatedf01dea2009-06-09 20:45:02 -0700108 * @param token A backup token as returned by {@link #getAvailableRestoreSets}.
Dan Egnorefe52642009-06-24 00:16:33 -0700109 * @param packages List of applications to restore (if data is available).
110 * Application data will be restored in the order given.
111 * @return false if errors occurred (the restore should be aborted and rescheduled),
112 * true if everything is OK so far (go ahead and call {@link #nextRestorePackage}).
Christopher Tateb4a61882009-06-07 15:19:32 -0700113 */
Dan Egnorefe52642009-06-24 00:16:33 -0700114 boolean startRestore(long token, in PackageInfo[] packages);
Christopher Tateb4a61882009-06-07 15:19:32 -0700115
116 /**
Dan Egnorefe52642009-06-24 00:16:33 -0700117 * Get the package name of the next application with data in the backup store.
118 * @return The name of one of the packages supplied to {@link #startRestore},
119 * or "" (the empty string) if no more backup data is available,
120 * or null if an error occurred (the restore should be aborted and rescheduled).
Christopher Tateb4a61882009-06-07 15:19:32 -0700121 */
Dan Egnorefe52642009-06-24 00:16:33 -0700122 String nextRestorePackage();
Christopher Tateb4a61882009-06-07 15:19:32 -0700123
124 /**
Dan Egnorefe52642009-06-24 00:16:33 -0700125 * Get the data for the application returned by {@link #nextRestorePackage}.
126 * @param data An open, writable file into which the backup data should be stored.
127 * @return false if errors occurred (the restore should be aborted and rescheduled),
128 * true if everything is OK so far (go ahead and call {@link #nextRestorePackage}).
Christopher Tatee10be802009-05-07 17:22:16 -0700129 */
Dan Egnorefe52642009-06-24 00:16:33 -0700130 boolean getRestoreData(in ParcelFileDescriptor outFd);
131
132 /**
133 * End a restore session (aborting any in-process data transfer as necessary),
134 * freeing any resources and connections used during the restore process.
135 */
136 void finishRestore();
Christopher Tate487529a2009-04-29 14:03:25 -0700137}