Merge "API: make "what's the quota?" an operation on the backup data sinks" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
78a00503db
@@ -6703,7 +6703,6 @@ package android.app.backup {
|
||||
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();
|
||||
@@ -6738,6 +6737,7 @@ package android.app.backup {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -6766,6 +6766,7 @@ package android.app.backup {
|
||||
}
|
||||
|
||||
public class FullBackupDataOutput {
|
||||
method public long getQuota();
|
||||
}
|
||||
|
||||
public abstract class RestoreObserver {
|
||||
|
||||
@@ -6952,7 +6952,6 @@ package android.app.backup {
|
||||
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();
|
||||
@@ -6989,6 +6988,8 @@ package android.app.backup {
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -7165,6 +7166,7 @@ package android.app.backup {
|
||||
}
|
||||
|
||||
public class FullBackupDataOutput {
|
||||
method public long getQuota();
|
||||
}
|
||||
|
||||
public class RestoreDescription implements android.os.Parcelable {
|
||||
|
||||
@@ -6733,7 +6733,6 @@ package android.app.backup {
|
||||
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();
|
||||
@@ -6768,6 +6767,7 @@ package android.app.backup {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -6796,6 +6796,7 @@ package android.app.backup {
|
||||
}
|
||||
|
||||
public class FullBackupDataOutput {
|
||||
method public long getQuota();
|
||||
}
|
||||
|
||||
public abstract class RestoreObserver {
|
||||
|
||||
@@ -133,8 +133,6 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
|
||||
Handler mHandler = null;
|
||||
|
||||
private long mBackupQuotaBytes = -1;
|
||||
|
||||
Handler getHandler() {
|
||||
if (mHandler == null) {
|
||||
mHandler = new Handler(Looper.getMainLooper());
|
||||
@@ -185,21 +183,6 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
public void onDestroy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -918,10 +901,8 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
// 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);
|
||||
@@ -937,9 +918,6 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
// guarantee themselves).
|
||||
waitForSharedPrefs();
|
||||
|
||||
// Unset quota after onBackup is done.
|
||||
mBackupQuotaBytes = -1;
|
||||
|
||||
Binder.restoreCallingIdentity(ident);
|
||||
try {
|
||||
callbackBinder.opComplete(token, 0);
|
||||
@@ -997,8 +975,6 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
// 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*
|
||||
@@ -1006,7 +982,7 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
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);
|
||||
@@ -1017,9 +993,6 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
// ... 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 {
|
||||
@@ -1046,9 +1019,7 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
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 {
|
||||
@@ -1060,8 +1031,6 @@ public abstract class BackupAgent extends ContextWrapper {
|
||||
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());
|
||||
|
||||
@@ -62,18 +62,39 @@ import java.io.IOException;
|
||||
* @see BackupAgent
|
||||
*/
|
||||
public class BackupDataOutput {
|
||||
final long mQuota;
|
||||
long mBackupWriter;
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
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}.
|
||||
|
||||
@@ -10,17 +10,35 @@ import android.os.ParcelFileDescriptor;
|
||||
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 */
|
||||
|
||||
Reference in New Issue
Block a user