Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96709414 authored by Neharika Jali's avatar Neharika Jali Committed by Android (Google) Code Review
Browse files

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

parents d58537d5 d5af2ead
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -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();