public abstract class BlobBackupHelper extends Object implements BackupHelper
Constructor and Description |
---|
BlobBackupHelper(int currentBlobVersion,
String... keys) |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
applyRestoredPayload(String key,
byte[] payload)
Given a byte array that was restored from backup, do whatever is appropriate
to apply that described state in the live system.
|
protected abstract byte[] |
getBackupPayload(String key)
Generate and return the byte array containing the backup payload describing
the current data state.
|
void |
performBackup(ParcelFileDescriptor oldStateFd,
BackupDataOutput data,
ParcelFileDescriptor newStateFd)
Based on
oldState , determine what application content
needs to be backed up, write it to data , and fill in
newState with the complete state as it exists now. |
void |
restoreEntity(BackupDataInputStream data)
Called by
BackupAgentHelper
to restore a single entity from the restore data set. |
void |
writeNewStateDescription(ParcelFileDescriptor newState)
Called by
BackupAgentHelper
after a restore operation to write the backup state file corresponding to
the data as processed by the helper. |
public BlobBackupHelper(int currentBlobVersion, String... keys)
protected abstract byte[] getBackupPayload(String key)
null
if the current state is empty or undefined.protected abstract void applyRestoredPayload(String key, byte[] payload)
payload
- The byte array that was passed to #getBackupPayload()
on the ancestral device.public void performBackup(ParcelFileDescriptor oldStateFd, BackupDataOutput data, ParcelFileDescriptor newStateFd)
BackupHelper
oldState
, determine what application content
needs to be backed up, write it to data
, and fill in
newState
with the complete state as it exists now.
Implementing this method is much like implementing
onBackup()
— the method parameters are the same. When this method is invoked the
oldState
descriptor points to the beginning of the state data
written during this helper's previous backup operation, and the newState
descriptor points to the file location at which the helper should write its
new state after performing the backup operation.
Note: The helper should not close or seek either the oldState
or
the newState
file descriptors. It is essential that when reading the helper's
saved state from the oldState
file, no extra content is consumed beyond
what was stored by this helper. If more old state data is read, even accidentally,
it will make it impossible for additional helpers that may be invoked after this one
to properly reconstruct their prior state.
performBackup
in interface BackupHelper
oldStateFd
- 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
- An open, read/write BackupDataOutput
pointing to the backup data destination.
Typically the application will use backup helper classes to
write to this file.newStateFd
- 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.public void restoreEntity(BackupDataInputStream data)
BackupHelper
BackupAgentHelper
to restore a single entity from the restore data set. This method will be
called for each entity in the data set that belongs to this handler.
Note: Do not close the data
stream. Do not read more than
size()
bytes from
data
.
restoreEntity
in interface BackupHelper
data
- An open BackupDataInputStream
from which the backup data can be read.public void writeNewStateDescription(ParcelFileDescriptor newState)
BackupHelper
BackupAgentHelper
after a restore operation to write the backup state file corresponding to
the data as processed by the helper. The data written here will be
available to the helper during the next call to its
performBackup()
method.
This method will be called even if the handler's
restoreEntity()
method was never invoked during
the restore operation.
Note: The helper should not close or seek the newState
file descriptor.
writeNewStateDescription
in interface BackupHelper
newState
- A ParcelFileDescriptor
to which the new state will be
written.