Save/load calculated cache quotas to a file.

This will prevent us from unnecessarily redoing calculation work
by loading the last caches on boot and shoving them down to
installd.

Bug: 33965858
Test: Framework services tests
Change-Id: Ie94e269aa72bceb1ebe87911eaa42e2d826c1123
This commit is contained in:
Daniel Nishi
2017-02-13 17:19:43 -08:00
parent e9f0fe9274
commit e40da3c1b7
4 changed files with 345 additions and 15 deletions

View File

@@ -24,8 +24,10 @@ import android.os.Parcelable;
import com.android.internal.util.Preconditions;
import java.util.Objects;
/**
* CacheQuotaRequest represents a triplet of a uid, the volume UUID it is stored upon, and
* CacheQuotaHint represents a triplet of a uid, the volume UUID it is stored upon, and
* its usage stats. When processed, it obtains a cache quota as defined by the system which
* allows apps to understand how much cache to use.
* {@hide}
@@ -78,6 +80,23 @@ public final class CacheQuotaHint implements Parcelable {
return 0;
}
@Override
public boolean equals(Object o) {
if (o instanceof CacheQuotaHint) {
final CacheQuotaHint other = (CacheQuotaHint) o;
return Objects.equals(mUuid, other.mUuid)
&& Objects.equals(mUsageStats, other.mUsageStats)
&& mUid == other.mUid && mQuota == other.mQuota;
}
return false;
}
@Override
public int hashCode() {
return Objects.hash(this.mUuid, this.mUid, this.mUsageStats, this.mQuota);
}
public static final class Builder {
private String mUuid;
private int mUid;
@@ -100,7 +119,7 @@ public final class CacheQuotaHint implements Parcelable {
}
public @NonNull Builder setUid(int uid) {
Preconditions.checkArgumentPositive(uid, "Proposed uid was not positive.");
Preconditions.checkArgumentNonnegative(uid, "Proposed uid was negative.");
mUid = uid;
return this;
}
@@ -117,7 +136,6 @@ public final class CacheQuotaHint implements Parcelable {
}
public @NonNull CacheQuotaHint build() {
Preconditions.checkNotNull(mUsageStats);
return new CacheQuotaHint(this);
}
}