| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.usage; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.annotation.SystemApi; |
| 22 |
import android.os.Parcel; |
| 23 |
import android.os.Parcelable; |
| 24 |
|
| 25 |
import com.android.internal.util.Preconditions; |
| 26 |
|
| 27 |
import java.util.Objects; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@SystemApi |
| 36 |
public final class CacheQuotaHint implements Parcelable { |
| 37 |
public static final long QUOTA_NOT_SET = -1; |
| 38 |
private final String mUuid; |
| 39 |
private final int mUid; |
| 40 |
private final UsageStats mUsageStats; |
| 41 |
private final long mQuota; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public CacheQuotaHint(@NonNull Builder builder) { |
| 48 |
this.mUuid = builder.mUuid; |
| 49 |
this.mUid = builder.mUid; |
| 50 |
this.mUsageStats = builder.mUsageStats; |
| 51 |
this.mQuota = builder.mQuota; |
| 52 |
} |
| 53 |
|
| 54 |
@Nullable public String getVolumeUuid() { |
| 55 |
return mUuid; |
| 56 |
} |
| 57 |
|
| 58 |
public int getUid() { |
| 59 |
return mUid; |
| 60 |
} |
| 61 |
|
| 62 |
public long getQuota() { |
| 63 |
return mQuota; |
| 64 |
} |
| 65 |
|
| 66 |
@Nullable public UsageStats getUsageStats() { |
| 67 |
return mUsageStats; |
| 68 |
} |
| 69 |
|
| 70 |
@Override |
| 71 |
public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 72 |
dest.writeString(mUuid); |
| 73 |
dest.writeInt(mUid); |
| 74 |
dest.writeLong(mQuota); |
| 75 |
dest.writeParcelable(mUsageStats, 0); |
| 76 |
} |
| 77 |
|
| 78 |
@Override |
| 79 |
public int describeContents() { |
| 80 |
return 0; |
| 81 |
} |
| 82 |
|
| 83 |
@Override |
| 84 |
public boolean equals(@Nullable Object o) { |
| 85 |
if (o instanceof CacheQuotaHint) { |
| 86 |
final CacheQuotaHint other = (CacheQuotaHint) o; |
| 87 |
return Objects.equals(mUuid, other.mUuid) |
| 88 |
&& Objects.equals(mUsageStats, other.mUsageStats) |
| 89 |
&& mUid == other.mUid && mQuota == other.mQuota; |
| 90 |
} |
| 91 |
|
| 92 |
return false; |
| 93 |
} |
| 94 |
|
| 95 |
@Override |
| 96 |
public int hashCode() { |
| 97 |
return Objects.hash(this.mUuid, this.mUid, this.mUsageStats, this.mQuota); |
| 98 |
} |
| 99 |
|
| 100 |
public static final class Builder { |
| 101 |
private String mUuid; |
| 102 |
private int mUid; |
| 103 |
private UsageStats mUsageStats; |
| 104 |
private long mQuota; |
| 105 |
|
| 106 |
public Builder() { |
| 107 |
} |
| 108 |
|
| 109 |
public Builder(@NonNull CacheQuotaHint hint) { |
| 110 |
setVolumeUuid(hint.getVolumeUuid()); |
| 111 |
setUid(hint.getUid()); |
| 112 |
setUsageStats(hint.getUsageStats()); |
| 113 |
setQuota(hint.getQuota()); |
| 114 |
} |
| 115 |
|
| 116 |
public @NonNull Builder setVolumeUuid(@Nullable String uuid) { |
| 117 |
mUuid = uuid; |
| 118 |
return this; |
| 119 |
} |
| 120 |
|
| 121 |
public @NonNull Builder setUid(int uid) { |
| 122 |
Preconditions.checkArgumentNonnegative(uid, "Proposed uid was negative."); |
| 123 |
mUid = uid; |
| 124 |
return this; |
| 125 |
} |
| 126 |
|
| 127 |
public @NonNull Builder setUsageStats(@Nullable UsageStats stats) { |
| 128 |
mUsageStats = stats; |
| 129 |
return this; |
| 130 |
} |
| 131 |
|
| 132 |
public @NonNull Builder setQuota(long quota) { |
| 133 |
Preconditions.checkArgument((quota >= QUOTA_NOT_SET)); |
| 134 |
mQuota = quota; |
| 135 |
return this; |
| 136 |
} |
| 137 |
|
| 138 |
public @NonNull CacheQuotaHint build() { |
| 139 |
return new CacheQuotaHint(this); |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
public static final @android.annotation.NonNull Parcelable.Creator<CacheQuotaHint> CREATOR = |
| 144 |
new Creator<CacheQuotaHint>() { |
| 145 |
@Override |
| 146 |
public CacheQuotaHint createFromParcel(Parcel in) { |
| 147 |
final Builder builder = new Builder(); |
| 148 |
return builder.setVolumeUuid(in.readString()) |
| 149 |
.setUid(in.readInt()) |
| 150 |
.setQuota(in.readLong()) |
| 151 |
.setUsageStats(in.readParcelable(UsageStats.class.getClassLoader(), android.app.usage.UsageStats.class)) |
| 152 |
.build(); |
| 153 |
} |
| 154 |
|
| 155 |
@Override |
| 156 |
public CacheQuotaHint[] newArray(int size) { |
| 157 |
return new CacheQuotaHint[size]; |
| 158 |
} |
| 159 |
}; |
| 160 |
} |