Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 69f42ecb authored by Shreyas Basarge's avatar Shreyas Basarge Committed by Android (Google) Code Review
Browse files

Merge "BackupAgent#getBackupQuota() API"

parents 349a8aef b6e73c96
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6604,6 +6604,7 @@ 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();
+1 −0
Original line number Diff line number Diff line
@@ -6841,6 +6841,7 @@ 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();
+1 −0
Original line number Diff line number Diff line
@@ -6627,6 +6627,7 @@ 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();
+7 −3
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ oneway interface IBackupAgent {
     * @param newState Read-write file, empty when onBackup() is called,
     *        where the new state blob is to be recorded.
     *
     * @param quota Quota reported by the transport for this backup operation (in bytes).
     *
     * @param token Opaque token identifying this transaction.  This must
     *        be echoed back to the backup service binder once the new
     *        data has been written to the data and newState files.
@@ -51,7 +53,7 @@ oneway interface IBackupAgent {
    void doBackup(in ParcelFileDescriptor oldState,
            in ParcelFileDescriptor data,
            in ParcelFileDescriptor newState,
            int token, IBackupManager callbackBinder);
            long quotaBytes, int token, IBackupManager callbackBinder);

    /**
     * Restore an entire data snapshot to the application.
@@ -89,6 +91,8 @@ oneway interface IBackupAgent {
     *        The data must be formatted correctly for the resulting archive to be
     *        legitimate, so that will be tightly controlled by the available API.
     *
     * @param quota Quota reported by the transport for this backup operation (in bytes).
     *
     * @param token Opaque token identifying this transaction.  This must
     *        be echoed back to the backup service binder once the agent is
     *        finished restoring the application based on the restore data
@@ -97,12 +101,12 @@ oneway interface IBackupAgent {
     * @param callbackBinder Binder on which to indicate operation completion,
     *        passed here as a convenience to the agent.
     */
    void doFullBackup(in ParcelFileDescriptor data, int token, IBackupManager callbackBinder);
    void doFullBackup(in ParcelFileDescriptor data, long quotaBytes, int token, IBackupManager callbackBinder);

    /**
     * Estimate how much data a full backup will deliver
     */
    void doMeasureFullBackup(int token, IBackupManager callbackBinder);
    void doMeasureFullBackup(long quotaBytes, int token, IBackupManager callbackBinder);

    /**
     * Tells the application agent that the backup data size exceeded current transport quota.
+34 −3
Original line number Diff line number Diff line
@@ -133,6 +133,8 @@ public abstract class BackupAgent extends ContextWrapper {

    Handler mHandler = null;

    private long mBackupQuotaBytes = -1;

    Handler getHandler() {
        if (mHandler == null) {
            mHandler = new Handler(Looper.getMainLooper());
@@ -183,6 +185,21 @@ 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
@@ -897,10 +914,12 @@ public abstract class BackupAgent extends ContextWrapper {
        public void doBackup(ParcelFileDescriptor oldState,
                ParcelFileDescriptor data,
                ParcelFileDescriptor newState,
                int token, IBackupManager callbackBinder) throws RemoteException {
                long quotaBytes, int token, IBackupManager callbackBinder) throws RemoteException {
            // 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());

@@ -918,6 +937,9 @@ 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);
@@ -971,10 +993,12 @@ public abstract class BackupAgent extends ContextWrapper {

        @Override
        public void doFullBackup(ParcelFileDescriptor data,
                int token, IBackupManager callbackBinder) {
                long quotaBytes, int token, IBackupManager callbackBinder) {
            // 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*
@@ -993,6 +1017,9 @@ 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 {
@@ -1016,11 +1043,13 @@ public abstract class BackupAgent extends ContextWrapper {
            }
        }

        public void doMeasureFullBackup(int token, IBackupManager callbackBinder) {
        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;

            waitForSharedPrefs();
            try {
                BackupAgent.this.onFullBackup(measureOutput);
@@ -1031,6 +1060,8 @@ 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());
Loading