Fix numerical overflow in result in computeStorageCacheBytes
Bug: 211756656 Test: atest atest frameworks/base/core/tests/coretests/src/android/os/storage/StorageManagerBaseTest#testGetStorageCacheBytesUnderModerateStorage Change-Id: I89fd358536708389d33e3077dcd0928332f5182f
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user