public abstract class BackupAgent extends android.content.ContextWrapper {
ctor public BackupAgent();
method public final void fullBackupFile(java.io.File, android.app.backup.FullBackupDataOutput);
- method public long getBackupQuota();
method public abstract void onBackup(android.os.ParcelFileDescriptor, android.app.backup.BackupDataOutput, android.os.ParcelFileDescriptor) throws java.io.IOException;
method public void onCreate();
method public void onDestroy();
}
public class BackupDataOutput {
+ method public long getQuota();
method public int writeEntityData(byte[], int) throws java.io.IOException;
method public int writeEntityHeader(java.lang.String, int) throws java.io.IOException;
}
}
public class FullBackupDataOutput {
+ method public long getQuota();
}
public abstract class RestoreObserver {
public abstract class BackupAgent extends android.content.ContextWrapper {
ctor public BackupAgent();
method public final void fullBackupFile(java.io.File, android.app.backup.FullBackupDataOutput);
- method public long getBackupQuota();
method public abstract void onBackup(android.os.ParcelFileDescriptor, android.app.backup.BackupDataOutput, android.os.ParcelFileDescriptor) throws java.io.IOException;
method public void onCreate();
method public void onDestroy();
public class BackupDataOutput {
ctor public BackupDataOutput(java.io.FileDescriptor);
+ ctor public BackupDataOutput(java.io.FileDescriptor, long);
+ method public long getQuota();
method public int writeEntityData(byte[], int) throws java.io.IOException;
method public int writeEntityHeader(java.lang.String, int) throws java.io.IOException;
}
}
public class FullBackupDataOutput {
+ method public long getQuota();
}
public class RestoreDescription implements android.os.Parcelable {
public abstract class BackupAgent extends android.content.ContextWrapper {
ctor public BackupAgent();
method public final void fullBackupFile(java.io.File, android.app.backup.FullBackupDataOutput);
- method public long getBackupQuota();
method public abstract void onBackup(android.os.ParcelFileDescriptor, android.app.backup.BackupDataOutput, android.os.ParcelFileDescriptor) throws java.io.IOException;
method public void onCreate();
method public void onDestroy();
}
public class BackupDataOutput {
+ method public long getQuota();
method public int writeEntityData(byte[], int) throws java.io.IOException;
method public int writeEntityHeader(java.lang.String, int) throws java.io.IOException;
}
}
public class FullBackupDataOutput {
+ method public long getQuota();
}
public abstract class RestoreObserver {
Handler mHandler = null;
- private long mBackupQuotaBytes = -1;
-
Handler getHandler() {
if (mHandler == null) {
mHandler = new Handler(Looper.getMainLooper());
}
/**
- * Returns the quota in bytes for the currently requested backup operation. The value can
- * vary for each operation depending on the type of backup being done.
- *
- * <p>Can be called only from {@link BackupAgent#onFullBackup(FullBackupDataOutput)} or
- * {@link BackupAgent#onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}.
- */
- public long getBackupQuota() {
- if (mBackupQuotaBytes < 0) {
- throw new IllegalStateException(
- "Backup quota is available only during backup operations.");
- }
- return mBackupQuotaBytes;
- }
-
- /**
* The application is being asked to write any data changed since the last
* time it performed a backup operation. The state data recorded during the
* last backup pass is provided in the <code>oldState</code> file
// Ensure that we're running with the app's normal permission level
long ident = Binder.clearCallingIdentity();
- mBackupQuotaBytes = quotaBytes;
-
if (DEBUG) Log.v(TAG, "doBackup() invoked");
- BackupDataOutput output = new BackupDataOutput(data.getFileDescriptor());
+ BackupDataOutput output = new BackupDataOutput(data.getFileDescriptor(), quotaBytes);
try {
BackupAgent.this.onBackup(oldState, output, newState);
// guarantee themselves).
waitForSharedPrefs();
- // Unset quota after onBackup is done.
- mBackupQuotaBytes = -1;
-
Binder.restoreCallingIdentity(ident);
try {
callbackBinder.opComplete(token, 0);
// Ensure that we're running with the app's normal permission level
long ident = Binder.clearCallingIdentity();
- mBackupQuotaBytes = quotaBytes;
-
if (DEBUG) Log.v(TAG, "doFullBackup() invoked");
// Ensure that any SharedPreferences writes have landed *before*
waitForSharedPrefs();
try {
- BackupAgent.this.onFullBackup(new FullBackupDataOutput(data));
+ BackupAgent.this.onFullBackup(new FullBackupDataOutput(data, quotaBytes));
} catch (IOException ex) {
Log.d(TAG, "onFullBackup (" + BackupAgent.this.getClass().getName() + ") threw", ex);
throw new RuntimeException(ex);
// ... and then again after, as in the doBackup() case
waitForSharedPrefs();
- // Unset quota after onFullBackup is done.
- mBackupQuotaBytes = -1;
-
// Send the EOD marker indicating that there is no more data
// forthcoming from this agent.
try {
public void doMeasureFullBackup(long quotaBytes, int token, IBackupManager callbackBinder) {
// Ensure that we're running with the app's normal permission level
final long ident = Binder.clearCallingIdentity();
- FullBackupDataOutput measureOutput = new FullBackupDataOutput();
-
- mBackupQuotaBytes = quotaBytes;
+ FullBackupDataOutput measureOutput = new FullBackupDataOutput(quotaBytes);
waitForSharedPrefs();
try {
Log.d(TAG, "onFullBackup[M] (" + BackupAgent.this.getClass().getName() + ") threw", ex);
throw ex;
} finally {
- // Unset quota after onFullBackup is done.
- mBackupQuotaBytes = -1;
Binder.restoreCallingIdentity(ident);
try {
callbackBinder.opComplete(token, measureOutput.getSize());
* @see BackupAgent
*/
public class BackupDataOutput {
+ final long mQuota;
long mBackupWriter;
- /** @hide */
+ /**
+ * Construct a BackupDataOutput purely for data-stream manipulation. This instance will
+ * not report usable quota information.
+ * @hide */
@SystemApi
public BackupDataOutput(FileDescriptor fd) {
+ this(fd, -1);
+ }
+
+ /** @hide */
+ @SystemApi
+ public BackupDataOutput(FileDescriptor fd, long quota) {
if (fd == null) throw new NullPointerException();
+ mQuota = quota;
mBackupWriter = ctor(fd);
if (mBackupWriter == 0) {
throw new RuntimeException("Native initialization failed with fd=" + fd);
}
/**
+ * Returns the quota in bytes for the application's current backup operation. The
+ * value can vary for each operation.
+ *
+ * @see FullBackupDataOutput#getQuota()
+ */
+ public long getQuota() {
+ return mQuota;
+ }
+
+ /**
* Mark the beginning of one record in the backup data stream. This must be called before
* {@link #writeEntityData}.
* @param key A string key that uniquely identifies the data record within the application.
public class FullBackupDataOutput {
// Currently a name-scoping shim around BackupDataOutput
private final BackupDataOutput mData;
+ private final long mQuota;
private long mSize;
+ /**
+ * Returns the quota in bytes for the application's current backup operation. The
+ * value can vary for each operation.
+ *
+ * @see BackupDataOutput#getQuota()
+ */
+ public long getQuota() {
+ return mQuota;
+ }
+
/** @hide - used only in measure operation */
- public FullBackupDataOutput() {
+ public FullBackupDataOutput(long quota) {
mData = null;
+ mQuota = quota;
mSize = 0;
}
/** @hide */
+ public FullBackupDataOutput(ParcelFileDescriptor fd, long quota) {
+ mData = new BackupDataOutput(fd.getFileDescriptor(), quota);
+ mQuota = quota;
+ }
+
+ /** @hide - used only internally to the backup manager service's stream construction */
public FullBackupDataOutput(ParcelFileDescriptor fd) {
- mData = new BackupDataOutput(fd.getFileDescriptor());
+ this(fd, -1);
}
/** @hide */