Loading core/java/android/os/storage/StorageManager.java +5 −4 Original line number Diff line number Diff line Loading @@ -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; } Loading core/tests/coretests/src/android/os/storage/StorageManagerBaseTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); } /** Loading Loading
core/java/android/os/storage/StorageManager.java +5 −4 Original line number Diff line number Diff line Loading @@ -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; } Loading
core/tests/coretests/src/android/os/storage/StorageManagerBaseTest.java +1 −1 Original line number Diff line number Diff line Loading @@ -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); } /** Loading