Loading core/java/android/os/FileUtils.java +23 −0 Original line number Diff line number Diff line Loading @@ -752,4 +752,27 @@ public class FileUtils { public static @Nullable File newFileOrNull(@Nullable String path) { return (path != null) ? new File(path) : null; } /** * Round the given size of a storage device to a nice round power-of-two * value, such as 256MB or 32GB. This avoids showing weird values like * "29.5GB" in UI. * * @hide */ public static long roundStorageSize(long size) { long val = 1; long pow = 1; long pow1024 = 1; while ((val * pow1024) < size) { val <<= 1; if (val > 512) { val = 1; pow *= 1000; pow1024 *= 1024; } } return val * pow; } } core/java/android/os/storage/StorageManager.java +1 −7 Original line number Diff line number Diff line Loading @@ -932,13 +932,7 @@ public class StorageManager { /** {@hide} */ public long getPrimaryStorageSize() { for (String path : INTERNAL_STORAGE_SIZE_PATHS) { final long numberBlocks = readLong(path); if (numberBlocks > 0) { return numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE; } } return 0; return FileUtils.roundStorageSize(Environment.getDataDirectory().getTotalSpace()); } private long readLong(String path) { Loading Loading
core/java/android/os/FileUtils.java +23 −0 Original line number Diff line number Diff line Loading @@ -752,4 +752,27 @@ public class FileUtils { public static @Nullable File newFileOrNull(@Nullable String path) { return (path != null) ? new File(path) : null; } /** * Round the given size of a storage device to a nice round power-of-two * value, such as 256MB or 32GB. This avoids showing weird values like * "29.5GB" in UI. * * @hide */ public static long roundStorageSize(long size) { long val = 1; long pow = 1; long pow1024 = 1; while ((val * pow1024) < size) { val <<= 1; if (val > 512) { val = 1; pow *= 1000; pow1024 *= 1024; } } return val * pow; } }
core/java/android/os/storage/StorageManager.java +1 −7 Original line number Diff line number Diff line Loading @@ -932,13 +932,7 @@ public class StorageManager { /** {@hide} */ public long getPrimaryStorageSize() { for (String path : INTERNAL_STORAGE_SIZE_PATHS) { final long numberBlocks = readLong(path); if (numberBlocks > 0) { return numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE; } } return 0; return FileUtils.roundStorageSize(Environment.getDataDirectory().getTotalSpace()); } private long readLong(String path) { Loading