Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 1 | package android.app.backup; |
| 2 | |
| 3 | import android.os.ParcelFileDescriptor; |
| 4 | |
| 5 | /** |
| 6 | * Provides the interface through which a {@link BackupAgent} writes entire files |
| 7 | * to a full backup data set, via its {@link BackupAgent#onFullBackup(FullBackupDataOutput)} |
| 8 | * method. |
| 9 | */ |
| 10 | public class FullBackupDataOutput { |
| 11 | // Currently a name-scoping shim around BackupDataOutput |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 12 | private final BackupDataOutput mData; |
Christopher Tate | ee87b96 | 2017-04-26 17:07:27 -0700 | [diff] [blame] | 13 | private final long mQuota; |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 14 | private final int mTransportFlags; |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 15 | private long mSize; |
| 16 | |
Christopher Tate | ee87b96 | 2017-04-26 17:07:27 -0700 | [diff] [blame] | 17 | /** |
| 18 | * Returns the quota in bytes for the application's current backup operation. The |
| 19 | * value can vary for each operation. |
| 20 | * |
| 21 | * @see BackupDataOutput#getQuota() |
| 22 | */ |
| 23 | public long getQuota() { |
| 24 | return mQuota; |
| 25 | } |
| 26 | |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 27 | /** |
| 28 | * Returns flags with additional information about the backup transport. For supported flags see |
| 29 | * {@link android.app.backup.BackupAgent} |
| 30 | * |
| 31 | * @see BackupDataOutput#getTransportFlags() |
| 32 | */ |
| 33 | public int getTransportFlags() { |
| 34 | return mTransportFlags; |
| 35 | } |
| 36 | |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 37 | /** @hide - used only in measure operation */ |
Christopher Tate | ee87b96 | 2017-04-26 17:07:27 -0700 | [diff] [blame] | 38 | public FullBackupDataOutput(long quota) { |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 39 | mData = null; |
Christopher Tate | ee87b96 | 2017-04-26 17:07:27 -0700 | [diff] [blame] | 40 | mQuota = quota; |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 41 | mSize = 0; |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 42 | mTransportFlags = 0; |
| 43 | } |
| 44 | |
| 45 | /** @hide - used only in measure operation */ |
| 46 | public FullBackupDataOutput(long quota, int transportFlags) { |
| 47 | mData = null; |
| 48 | mQuota = quota; |
| 49 | mSize = 0; |
| 50 | mTransportFlags = transportFlags; |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 51 | } |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 52 | |
| 53 | /** @hide */ |
Christopher Tate | ee87b96 | 2017-04-26 17:07:27 -0700 | [diff] [blame] | 54 | public FullBackupDataOutput(ParcelFileDescriptor fd, long quota) { |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 55 | mData = new BackupDataOutput(fd.getFileDescriptor(), quota, 0); |
Christopher Tate | ee87b96 | 2017-04-26 17:07:27 -0700 | [diff] [blame] | 56 | mQuota = quota; |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 57 | mTransportFlags = 0; |
| 58 | } |
| 59 | |
| 60 | /** @hide */ |
| 61 | public FullBackupDataOutput(ParcelFileDescriptor fd, long quota, int transportFlags) { |
| 62 | mData = new BackupDataOutput(fd.getFileDescriptor(), quota, transportFlags); |
| 63 | mQuota = quota; |
| 64 | mTransportFlags = transportFlags; |
Christopher Tate | ee87b96 | 2017-04-26 17:07:27 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** @hide - used only internally to the backup manager service's stream construction */ |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 68 | public FullBackupDataOutput(ParcelFileDescriptor fd) { |
Robert Berry | 39194c0 | 2018-01-11 13:50:56 +0000 | [diff] [blame] | 69 | this(fd, /*quota=*/ -1, /*transportFlags=*/ 0); |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** @hide */ |
| 73 | public BackupDataOutput getData() { return mData; } |
Christopher Tate | 11ae768 | 2015-03-24 18:48:10 -0700 | [diff] [blame] | 74 | |
| 75 | /** @hide - used for measurement pass */ |
| 76 | public void addSize(long size) { |
| 77 | if (size > 0) { |
| 78 | mSize += size; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** @hide - used for measurement pass */ |
| 83 | public long getSize() { return mSize; } |
Christopher Tate | 79ec80d | 2011-06-24 14:58:49 -0700 | [diff] [blame] | 84 | } |