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

Commit 7200364e authored by Sergey Poromov's avatar Sergey Poromov Committed by Android (Google) Code Review
Browse files

Merge "Quota exceeded API in BackupAgent"

parents 800133d4 872d3b6e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -6105,6 +6105,7 @@ package android.app.backup {
    method public void onCreate();
    method public void onDestroy();
    method public void onFullBackup(android.app.backup.FullBackupDataOutput) throws java.io.IOException;
    method public void onQuotaExceeded(long, long);
    method public abstract void onRestore(android.app.backup.BackupDataInput, int, android.os.ParcelFileDescriptor) throws java.io.IOException;
    method public void onRestoreFile(android.os.ParcelFileDescriptor, long, java.io.File, int, long, long) throws java.io.IOException;
    method public void onRestoreFinished();
+4 −0
Original line number Diff line number Diff line
@@ -6254,6 +6254,7 @@ package android.app.backup {
    method public void onCreate();
    method public void onDestroy();
    method public void onFullBackup(android.app.backup.FullBackupDataOutput) throws java.io.IOException;
    method public void onQuotaExceeded(long, long);
    method public abstract void onRestore(android.app.backup.BackupDataInput, int, android.os.ParcelFileDescriptor) throws java.io.IOException;
    method public void onRestoreFile(android.os.ParcelFileDescriptor, long, java.io.File, int, long, long) throws java.io.IOException;
    method public void onRestoreFinished();
@@ -6316,6 +6317,7 @@ package android.app.backup {
    field public static final int ERROR_PACKAGE_NOT_FOUND = -2002; // 0xfffff82e
    field public static final int ERROR_TRANSPORT_ABORTED = -1000; // 0xfffffc18
    field public static final int ERROR_TRANSPORT_PACKAGE_REJECTED = -1002; // 0xfffffc16
    field public static final int ERROR_TRANSPORT_QUOTA_EXCEEDED = -1005; // 0xfffffc13
    field public static final int SUCCESS = 0; // 0x0
  }
@@ -6348,6 +6350,7 @@ package android.app.backup {
    method public int finishBackup();
    method public void finishRestore();
    method public android.app.backup.RestoreSet[] getAvailableRestoreSets();
    method public long getBackupQuota(java.lang.String, boolean);
    method public android.os.IBinder getBinder();
    method public long getCurrentRestoreSet();
    method public int getNextFullRestoreDataChunk(android.os.ParcelFileDescriptor);
@@ -6373,6 +6376,7 @@ package android.app.backup {
    field public static final int TRANSPORT_NOT_INITIALIZED = -1001; // 0xfffffc17
    field public static final int TRANSPORT_OK = 0; // 0x0
    field public static final int TRANSPORT_PACKAGE_REJECTED = -1002; // 0xfffffc16
    field public static final int TRANSPORT_QUOTA_EXCEEDED = -1005; // 0xfffffc13
  }
  public class FileBackupHelper extends android.app.backup.FileBackupHelperBase implements android.app.backup.BackupHelper {
+1 −0
Original line number Diff line number Diff line
@@ -6107,6 +6107,7 @@ package android.app.backup {
    method public void onCreate();
    method public void onDestroy();
    method public void onFullBackup(android.app.backup.FullBackupDataOutput) throws java.io.IOException;
    method public void onQuotaExceeded(long, long);
    method public abstract void onRestore(android.app.backup.BackupDataInput, int, android.os.ParcelFileDescriptor) throws java.io.IOException;
    method public void onRestoreFile(android.os.ParcelFileDescriptor, long, java.io.File, int, long, long) throws java.io.IOException;
    method public void onRestoreFinished();
+21 −0
Original line number Diff line number Diff line
@@ -104,6 +104,27 @@ oneway interface IBackupAgent {
     */
    void doMeasureFullBackup(int token, IBackupManager callbackBinder);

    /**
     * Tells the application agent that the backup data size exceeded current transport quota.
     * Later calls to {@link #onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}
     * and {@link #onFullBackup(FullBackupDataOutput)} could use this information
     * to reduce backup size under the limit.
     * However, the quota can change, so do not assume that the value passed in here is absolute,
     * similarly all subsequent backups should not be restricted to this size.
     * This callback will be invoked before data has been put onto the wire in a preflight check,
     * so it is relatively inexpensive to hit your quota.
     * Apps that hit quota repeatedly without dealing with it can be subject to having their backup
     * schedule reduced.
     * The {@code quotaBytes} is a loose guideline b/c of metadata added by the backupmanager
     * so apps should be more aggressive in trimming their backup set.
     *
     * @param backupDataBytes Expected or already processed amount of data.
     *                        Could be less than total backup size if backup process was interrupted
     *                        before finish of processing all backup data.
     * @param quotaBytes Current amount of backup data that is allowed for the app.
     */
    void doQuotaExceeded(long backupDataBytes, long quotaBytes);

    /**
     * Restore a single "file" to the application.  The file was typically obtained from
     * a full-backup dataset.  The agent reads 'size' bytes of file content
+37 −0
Original line number Diff line number Diff line
@@ -381,6 +381,28 @@ public abstract class BackupAgent extends ContextWrapper {
        }
    }

    /**
     * Tells the application agent that the backup data size exceeded current transport quota.
     * Later calls to {@link #onBackup(ParcelFileDescriptor, BackupDataOutput, ParcelFileDescriptor)}
     * and {@link #onFullBackup(FullBackupDataOutput)} could use this information
     * to reduce backup size under the limit.
     * However, the quota can change, so do not assume that the value passed in here is absolute,
     * similarly all subsequent backups should not be restricted to this size.
     * This callback will be invoked before data has been put onto the wire in a preflight check,
     * so it is relatively inexpensive to hit your quota.
     * Apps that hit quota repeatedly without dealing with it can be subject to having their backup
     * schedule reduced.
     * The {@code quotaBytes} is a loose guideline b/c of metadata added by the backupmanager
     * so apps should be more aggressive in trimming their backup set.
     *
     * @param backupDataBytes Expected or already processed amount of data.
     *                        Could be less than total backup size if backup process was interrupted
     *                        before finish of processing all backup data.
     * @param quotaBytes Current amount of backup data that is allowed for the app.
     */
    public void onQuotaExceeded(long backupDataBytes, long quotaBytes) {
    }

    /**
     * Check whether the xml yielded any <include/> tag for the provided <code>domainToken</code>.
     * If so, perform a {@link #fullBackupFileTree} which backs up the file or recurses if the path
@@ -955,6 +977,21 @@ public abstract class BackupAgent extends ContextWrapper {
        public void fail(String message) {
            getHandler().post(new FailRunnable(message));
        }

        @Override
        public void doQuotaExceeded(long backupDataBytes, long quotaBytes) {
            long ident = Binder.clearCallingIdentity();
            try {
                BackupAgent.this.onQuotaExceeded(backupDataBytes, quotaBytes);
            } catch (Exception e) {
                Log.d(TAG, "onQuotaExceeded(" + BackupAgent.this.getClass().getName() + ") threw",
                        e);
                throw e;
            } finally {
                waitForSharedPrefs();
                Binder.restoreCallingIdentity(ident);
            }
        }
    }

    static class FailRunnable implements Runnable {
Loading