Merge "In low storage, recalculate cache quotas if 2% change in total space"

This commit is contained in:
Neharika Jali
2021-12-16 08:14:52 +00:00
committed by Android (Google) Code Review

View File

@@ -552,23 +552,26 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
private static final int MSG_PACKAGE_REMOVED = 103;
/**
* By only triggering a re-calculation after the storage has changed sizes, we can avoid
* recalculating quotas too often. Minimum change delta defines the percentage of change
* we need to see before we recalculate.
* recalculating quotas too often. Minimum change delta high and low define the
* percentage of change we need to see before we recalculate quotas when the device has
* enough storage space (more than StorageManager.STORAGE_THRESHOLD_PERCENT_HIGH of total
* free) and in low storage condition respectively.
*/
private static final double MINIMUM_CHANGE_DELTA = 0.05;
private static final long MINIMUM_CHANGE_DELTA_PERCENT_HIGH = 5;
private static final long MINIMUM_CHANGE_DELTA_PERCENT_LOW = 2;
private static final int UNSET = -1;
private static final boolean DEBUG = false;
private final StatFs mStats;
private long mPreviousBytes;
private double mMinimumThresholdBytes;
private long mTotalBytes;
public H(Looper looper) {
super(looper);
// TODO: Handle all private volumes.
mStats = new StatFs(Environment.getDataDirectory().getAbsolutePath());
mPreviousBytes = mStats.getAvailableBytes();
mMinimumThresholdBytes = mStats.getTotalBytes() * MINIMUM_CHANGE_DELTA;
mTotalBytes = mStats.getTotalBytes();
}
public void handleMessage(Message msg) {
@@ -584,7 +587,14 @@ public class StorageStatsService extends IStorageStatsManager.Stub {
case MSG_CHECK_STORAGE_DELTA: {
mStats.restat(Environment.getDataDirectory().getAbsolutePath());
long bytesDelta = Math.abs(mPreviousBytes - mStats.getAvailableBytes());
if (bytesDelta > mMinimumThresholdBytes) {
long bytesDeltaThreshold;
if (mStats.getAvailableBytes() > mTotalBytes
* StorageManager.STORAGE_THRESHOLD_PERCENT_HIGH / 100) {
bytesDeltaThreshold = mTotalBytes * MINIMUM_CHANGE_DELTA_PERCENT_HIGH / 100;
} else {
bytesDeltaThreshold = mTotalBytes * MINIMUM_CHANGE_DELTA_PERCENT_LOW / 100;
}
if (bytesDelta > bytesDeltaThreshold) {
mPreviousBytes = mStats.getAvailableBytes();
recalculateQuotas(getInitializedStrategy());
notifySignificantDelta();