public class BackupAgentHelper extends BackupAgent
BackupAgent
wrapper class that automatically manages
heterogeneous data sets within the backup data, each identified by a unique
key prefix. When processing a backup or restore operation, the BackupAgentHelper
dispatches to one or more installed BackupHelper
objects, each
of which is responsible for a defined subset of the data being processed.
An application will typically extend this class in its own
backup agent. Then, within the agent's onCreate()
method, it will call addHelper()
one or more times to
install the handlers for each kind of data it wishes to manage within its backups.
The Android framework currently provides two predefined BackupHelper
classes:
FileBackupHelper
- Manages the backup and restore of entire files
within an application's data directory hierarchy.SharedPreferencesBackupHelper
- Manages the backup and restore of an
application's SharedPreferences
data.
An application can also implement its own helper classes to work within the
BackupAgentHelper
framework. See the BackupHelper
interface
documentation for details.
For more information about using BackupAgentHelper, read the Data Backup developer guide.
TYPE_DIRECTORY, TYPE_EOF, TYPE_FILE, TYPE_SYMLINK
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APPWIDGET_SERVICE, AUDIO_SERVICE, BACKUP_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_NOT_VISIBLE, BIND_VISIBLE, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, COUNTRY_DETECTOR, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_ROUTER_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NETWORK_POLICY_SERVICE, NETWORK_STATS_SERVICE, NETWORKMANAGEMENT_SERVICE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, SCHEDULING_POLICY_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, SERIAL_SERVICE, SIP_SERVICE, STATUS_BAR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, THROTTLE_SERVICE, UI_MODE_SERVICE, UPDATE_LOCK_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
Constructor and Description |
---|
BackupAgentHelper() |
Modifier and Type | Method and Description |
---|---|
void |
addHelper(String keyPrefix,
BackupHelper helper)
Add a helper for a given data subset to the agent's configuration.
|
BackupHelperDispatcher |
getDispatcher() |
void |
onBackup(ParcelFileDescriptor oldState,
BackupDataOutput data,
ParcelFileDescriptor newState)
Run the backup process on each of the configured handlers.
|
void |
onRestore(BackupDataInput data,
int appVersionCode,
ParcelFileDescriptor newState)
Run the restore process on each of the configured handlers.
|
attach, fullBackupFile, fullBackupFileTree, onBind, onCreate, onDestroy, onFullBackup, onRestoreFile, onRestoreFile
attachBaseContext, bindService, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createDisplayContext, createPackageContext, createPackageContextAsUser, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getCompatibilityInfo, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSharedPrefsFile, getSystemService, getTheme, getThemeResId, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, registerReceiverAsUser, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivitiesAsUser, startActivity, startActivity, startActivityAsUser, startActivityAsUser, startInstrumentation, startIntentSender, startIntentSender, startService, startServiceAsUser, stopService, stopServiceAsUser, unbindService, unregisterReceiver
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) throws IOException
onBackup
in class BackupAgent
oldState
- An open, read-only ParcelFileDescriptor pointing to the
last backup state provided by the application. May be
null
, in which case no prior state is being
provided and the application should perform a full backup.data
- A structured wrapper around an open, read/write
file descriptor pointing to the backup data destination.
Typically the application will use backup helper classes to
write to this file.newState
- An open, read/write ParcelFileDescriptor pointing to an
empty file. The application should record the final backup
state here after writing the requested data to the data
output stream.IOException
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) throws IOException
onRestore
in class BackupAgent
data
- A structured wrapper around an open, read-only
file descriptor pointing to a full snapshot of the
application's data. The application should consume every
entity represented in this data stream.appVersionCode
- The value of the android:versionCode
manifest attribute,
from the application that backed up this particular data set. This
makes it possible for an application's agent to distinguish among any
possible older data versions when asked to perform the restore
operation.newState
- An open, read/write ParcelFileDescriptor pointing to an
empty file. The application should record the final backup
state here after restoring its data from the data
stream.
When a full-backup dataset is being restored, this will be null
.IOException
public BackupHelperDispatcher getDispatcher()
public void addHelper(String keyPrefix, BackupHelper helper)
keyPrefix
- A string used to disambiguate the various helpers within this agenthelper
- A backup/restore helper object to be invoked during backup and restore
operations.