| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.blob; |
| 18 |
|
| 19 |
import static android.text.format.Formatter.FLAG_IEC_UNITS; |
| 20 |
|
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.app.AppGlobals; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
import android.text.format.Formatter; |
| 26 |
|
| 27 |
import java.util.Collections; |
| 28 |
import java.util.List; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public final class BlobInfo implements Parcelable { |
| 36 |
private final long mId; |
| 37 |
private final long mExpiryTimeMs; |
| 38 |
private final CharSequence mLabel; |
| 39 |
private final long mSizeBytes; |
| 40 |
private final List<LeaseInfo> mLeaseInfos; |
| 41 |
|
| 42 |
public BlobInfo(long id, long expiryTimeMs, CharSequence label, long sizeBytes, |
| 43 |
List<LeaseInfo> leaseInfos) { |
| 44 |
mId = id; |
| 45 |
mExpiryTimeMs = expiryTimeMs; |
| 46 |
mLabel = label; |
| 47 |
mSizeBytes = sizeBytes; |
| 48 |
mLeaseInfos = leaseInfos; |
| 49 |
} |
| 50 |
|
| 51 |
@SuppressWarnings("UnsafeParcelApi") |
| 52 |
private BlobInfo(Parcel in) { |
| 53 |
mId = in.readLong(); |
| 54 |
mExpiryTimeMs = in.readLong(); |
| 55 |
mLabel = in.readCharSequence(); |
| 56 |
mSizeBytes = in.readLong(); |
| 57 |
mLeaseInfos = in.readArrayList(null ); |
| 58 |
} |
| 59 |
|
| 60 |
public long getId() { |
| 61 |
return mId; |
| 62 |
} |
| 63 |
|
| 64 |
public long getExpiryTimeMs() { |
| 65 |
return mExpiryTimeMs; |
| 66 |
} |
| 67 |
|
| 68 |
public CharSequence getLabel() { |
| 69 |
return mLabel; |
| 70 |
} |
| 71 |
|
| 72 |
public long getSizeBytes() { |
| 73 |
return mSizeBytes; |
| 74 |
} |
| 75 |
|
| 76 |
public List<LeaseInfo> getLeases() { |
| 77 |
return Collections.unmodifiableList(mLeaseInfos); |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 82 |
dest.writeLong(mId); |
| 83 |
dest.writeLong(mExpiryTimeMs); |
| 84 |
dest.writeCharSequence(mLabel); |
| 85 |
dest.writeLong(mSizeBytes); |
| 86 |
dest.writeList(mLeaseInfos); |
| 87 |
} |
| 88 |
|
| 89 |
@Override |
| 90 |
public String toString() { |
| 91 |
return toShortString(); |
| 92 |
} |
| 93 |
|
| 94 |
private String toShortString() { |
| 95 |
return "BlobInfo {" |
| 96 |
+ "id: " + mId + "," |
| 97 |
+ "expiryMs: " + mExpiryTimeMs + "," |
| 98 |
+ "label: " + mLabel + "," |
| 99 |
+ "size: " + formatBlobSize(mSizeBytes) + "," |
| 100 |
+ "leases: " + LeaseInfo.toShortString(mLeaseInfos) + "," |
| 101 |
+ "}"; |
| 102 |
} |
| 103 |
|
| 104 |
private static String formatBlobSize(long sizeBytes) { |
| 105 |
return Formatter.formatFileSize(AppGlobals.getInitialApplication(), |
| 106 |
sizeBytes, FLAG_IEC_UNITS); |
| 107 |
} |
| 108 |
|
| 109 |
@Override |
| 110 |
public int describeContents() { |
| 111 |
return 0; |
| 112 |
} |
| 113 |
|
| 114 |
@NonNull |
| 115 |
public static final Creator<BlobInfo> CREATOR = new Creator<BlobInfo>() { |
| 116 |
@Override |
| 117 |
@NonNull |
| 118 |
public BlobInfo createFromParcel(Parcel source) { |
| 119 |
return new BlobInfo(source); |
| 120 |
} |
| 121 |
|
| 122 |
@Override |
| 123 |
@NonNull |
| 124 |
public BlobInfo[] newArray(int size) { |
| 125 |
return new BlobInfo[size]; |
| 126 |
} |
| 127 |
}; |
| 128 |
} |