Debian Codegraph @

apex/blobstore/framework/java/android/app/blob/BlobInfo.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 * Class to provide information about a shared blob.
32 *
33 * @hide
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 /* classloader */);
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 }