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