From d5af2ead56f6c2f209d96ac3909b4cc92bb64f99 Mon Sep 17 00:00:00 2001 From: Neharika Jali Date: Wed, 20 Oct 2021 06:55:04 +0000 Subject: [PATCH] In low storage, recalculate cache quotas if 2% change in total space Bug: 203651230 Test: manual Change-Id: Ie5df873f41e0bd0beca430b8e8ec51d5305bb844 --- .../server/usage/StorageStatsService.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/services/usage/java/com/android/server/usage/StorageStatsService.java b/services/usage/java/com/android/server/usage/StorageStatsService.java index 2d3b9286d69af..88725a6ea1b9a 100644 --- a/services/usage/java/com/android/server/usage/StorageStatsService.java +++ b/services/usage/java/com/android/server/usage/StorageStatsService.java @@ -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();