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

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

Merge "Fix numerical overflow in result in computeStorageCacheBytes"

parents 144be64a 4bf22b5e
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -1525,10 +1525,11 @@ public class StorageManager {
            result = totalBytes * CACHE_RESERVE_PERCENT_LOW / 100;
        } else {
            // Else, linearly interpolate the amount of space to reserve
            result = ((CACHE_RESERVE_PERCENT_HIGH - CACHE_RESERVE_PERCENT_LOW)
                      * (usableBytes - storageThresholdHighBytes) + CACHE_RESERVE_PERCENT_HIGH
                      * (storageThresholdHighBytes - storageThresholdLowBytes)) * totalBytes
                      / (100 * (storageThresholdHighBytes - storageThresholdLowBytes));
            double slope = (CACHE_RESERVE_PERCENT_HIGH - CACHE_RESERVE_PERCENT_LOW) * totalBytes
                    / (100.0 * (storageThresholdHighBytes - storageThresholdLowBytes));
            double intercept = totalBytes * CACHE_RESERVE_PERCENT_LOW / 100.0
                    - storageThresholdLowBytes * slope;
            result = Math.round(slope * usableBytes + intercept);
        }
        return result;
    }
+1 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ public class StorageManagerBaseTest extends InstrumentationTestCase {
        when(mFile.getUsableSpace()).thenReturn(10000L);
        when(mFile.getTotalSpace()).thenReturn(100000L);
        long result = mSm.getStorageCacheBytes(mFile, 0);
        assertThat(result).isEqualTo(4666L);
        assertThat(result).isEqualTo(4667L);
    }

    /**