Joe Onorato | 1cf5874 | 2009-06-12 11:06:24 -0700 | [diff] [blame] | 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 | |
Christopher Tate | 4528186 | 2010-03-05 15:46:30 -0800 | [diff] [blame] | 17 | package android.app.backup; |
Joe Onorato | 1cf5874 | 2009-06-12 11:06:24 -0700 | [diff] [blame] | 18 | |
Joe Onorato | d2d9ceb | 2009-06-18 13:11:18 -0700 | [diff] [blame] | 19 | import android.os.ParcelFileDescriptor; |
| 20 | |
Christopher Tate | e28290e | 2010-02-16 15:22:26 -0800 | [diff] [blame] | 21 | /** |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 22 | * Defines the calling interface that {@link BackupAgentHelper} uses |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 23 | * when dispatching backup and restore operations to the installed helpers. |
| 24 | * Applications can define and install their own helpers as well as using those |
| 25 | * provided as part of the Android framework. |
Kenny Root | 5a20ea1 | 2010-02-23 18:49:11 -0800 | [diff] [blame] | 26 | * <p> |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 27 | * Although multiple helper objects may be installed simultaneously, each helper |
| 28 | * is responsible only for handling its own data, and will not see entities |
| 29 | * created by other components within the backup system. Invocations of multiple |
| 30 | * helpers are performed sequentially by the {@link BackupAgentHelper}, with each |
| 31 | * helper given a chance to access its own saved state from within the state record |
| 32 | * produced during the previous backup operation. |
| 33 | * |
| 34 | * @see BackupAgentHelper |
| 35 | * @see FileBackupHelper |
| 36 | * @see SharedPreferencesBackupHelper |
Christopher Tate | e28290e | 2010-02-16 15:22:26 -0800 | [diff] [blame] | 37 | */ |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 38 | public interface BackupHelper { |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 39 | /** |
Kenny Root | 5a20ea1 | 2010-02-23 18:49:11 -0800 | [diff] [blame] | 40 | * Based on <code>oldState</code>, determine which of the files from the |
| 41 | * application's data directory need to be backed up, write them to |
| 42 | * <code>data</code>, and fill in <code>newState</code> with the state as it |
| 43 | * exists now. |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 44 | * <p> |
| 45 | * Implementing this method is much like implementing |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 46 | * {@link BackupAgent#onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor) |
| 47 | * onBackup()} — the method parameters are the same. When this method is invoked the |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 48 | * {@code oldState} descriptor points to the beginning of the state data |
| 49 | * written during this helper's previous backup operation, and the {@code newState} |
| 50 | * descriptor points to the file location at which the helper should write its |
| 51 | * new state after performing the backup operation. |
| 52 | * <p class="note"> |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 53 | * <strong>Note:</strong> The helper should not close or seek either the {@code oldState} or |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 54 | * the {@code newState} file descriptors.</p> |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 55 | * |
| 56 | * @param oldState An open, read-only {@link android.os.ParcelFileDescriptor} pointing to the |
| 57 | * last backup state provided by the application. May be |
| 58 | * <code>null</code>, in which case no prior state is being |
| 59 | * provided and the application should perform a full backup. |
| 60 | * @param data An open, read/write {@link BackupDataOutput} |
| 61 | * pointing to the backup data destination. |
| 62 | * Typically the application will use backup helper classes to |
| 63 | * write to this file. |
| 64 | * @param newState An open, read/write {@link android.os.ParcelFileDescriptor} pointing to an |
| 65 | * empty file. The application should record the final backup |
| 66 | * state here after writing the requested data to the <code>data</code> |
| 67 | * output stream. |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 68 | */ |
| 69 | public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, |
| 70 | ParcelFileDescriptor newState); |
| 71 | |
| 72 | /** |
Christopher Tate | cc84c69 | 2010-03-29 14:54:02 -0700 | [diff] [blame] | 73 | * Called by {@link android.app.backup.BackupAgentHelper BackupAgentHelper} |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 74 | * to restore a single entity from the restore data set. This method will be |
| 75 | * called for each entity in the data set that belongs to this handler. |
| 76 | * <p class="note"> |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 77 | * <strong>Note:</strong> Do not close the <code>data</code> stream. Do not read more than |
| 78 | * {@link android.app.backup.BackupDataInputStream#size() size()} bytes from |
| 79 | * <code>data</code>.</p> |
| 80 | * |
| 81 | * @param data An open {@link BackupDataInputStream} from which the backup data can be read. |
Joe Onorato | 5f15d15 | 2009-06-16 16:31:35 -0400 | [diff] [blame] | 82 | */ |
Joe Onorato | efd0fab | 2009-06-17 16:20:55 -0700 | [diff] [blame] | 83 | public void restoreEntity(BackupDataInputStream data); |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
Christopher Tate | cc84c69 | 2010-03-29 14:54:02 -0700 | [diff] [blame] | 86 | * Called by {@link android.app.backup.BackupAgentHelper BackupAgentHelper} |
Christopher Tate | 4e14a82 | 2010-04-08 12:54:23 -0700 | [diff] [blame] | 87 | * after a restore operation to write the backup state file corresponding to |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 88 | * the data as processed by the helper. The data written here will be |
| 89 | * available to the helper during the next call to its |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 90 | * {@link #performBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor) |
| 91 | * performBackup()} method. |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 92 | * <p> |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 93 | * This method will be called even if the handler's |
| 94 | * {@link #restoreEntity(BackupDataInputStream) restoreEntity()} method was never invoked during |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 95 | * the restore operation. |
| 96 | * <p class="note"> |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 97 | * <strong>Note:</strong> The helper should not close or seek the {@code newState} |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 98 | * file descriptor.</p> |
Scott Main | d17da43 | 2010-04-29 21:42:58 -0700 | [diff] [blame] | 99 | * |
| 100 | * @param newState A {@link android.os.ParcelFileDescriptor} to which the new state will be |
| 101 | * written. |
Joe Onorato | 06290a4 | 2009-06-18 20:10:37 -0700 | [diff] [blame] | 102 | */ |
Christopher Tate | 7cc0882 | 2010-04-12 18:24:05 -0700 | [diff] [blame] | 103 | public void writeNewStateDescription(ParcelFileDescriptor newState); |
Joe Onorato | 1cf5874 | 2009-06-12 11:06:24 -0700 | [diff] [blame] | 104 | } |
| 105 | |