diff options
| author | Jeff Sharkey <jsharkey@android.com> | 2017-03-07 20:50:27 -0700 |
|---|---|---|
| committer | Jeff Sharkey <jsharkey@android.com> | 2017-03-07 20:52:29 -0700 |
| commit | 09734df8bc5a2b788c923ec1a8b78e4cb67f5e70 (patch) | |
| tree | b5d1761995635801b772139c77b9a3f4c7c940f2 /core/java/android/os/FileUtils.java | |
| parent | c7eefdbda7864c71f2bc1845e83d9a21aa10c338 (diff) | |
Grumble, nobody likes kibibytes.
All the cool kids are using storage in increments of 1000 instead
of 1024, so find a balance somewhere between the two. We still round
to nice values like 32GB, 64GB, etc, but we represent them using
kilobytes under the hood.
Test: runtest -x frameworks/base/core/tests/coretests/src/android/os/FileUtilsTest.java
Bug: 28327846
Change-Id: I573aea43790816291e2b5c784b344b51b4444c06
Diffstat (limited to 'core/java/android/os/FileUtils.java')
| -rw-r--r-- | core/java/android/os/FileUtils.java | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java index af05ee7978ce..50b4f8c7facf 100644 --- a/core/java/android/os/FileUtils.java +++ b/core/java/android/os/FileUtils.java @@ -777,10 +777,15 @@ public class FileUtils { * "29.5GB" in UI. */ public static long roundStorageSize(long size) { - long res = 1; - while (res < size) { - res <<= 1; + long val = 1; + long pow = 1; + while ((val * pow) < size) { + val <<= 1; + if (val > 512) { + val = 1; + pow *= 1000; + } } - return res; + return val * pow; } } |
