Improved storage size detection.

The total storage size was calculating by reading and multiplying the
contents of /sys/block/mmcblk0/size and
/sys/block/mmcblk0/queue/hw_sector_size.

On some devices, such calculation doesn't work because:

1.The primary block is not /sys/block/mmcblk0 .
2.The sector size is not the right value to use.

These 2 issues are temporarily addressed by providing alternative
primary blocks and hardcoding the size (512 bytes). In the long term,
the size should be calculated by vold, so each device could provide its
own calculation if necessary.

BUG: 30216622
Change-Id: I8f9a9f4f753d3c92bab9257062b61ed2b9d665c5
Fixes: 24128505
This commit is contained in:
Felipe Leme
2016-07-19 09:33:31 -07:00
parent fb0ec9de84
commit 179923a611

View File

@@ -132,10 +132,15 @@ public class StorageManager {
public static final int FLAG_INCLUDE_INVISIBLE = 1 << 10;
private static volatile IMountService sMountService = null;
private static final String INTERNAL_STORAGE_SIZE_PATH =
"/sys/block/mmcblk0/size";
private static final String INTERNAL_STORAGE_SECTOR_SIZE =
"/sys/block/mmcblk0/queue/hw_sector_size";
// TODO: the location of the primary storage block varies from device to device, so we need to
// try the most likely candidates - a long-term solution would be a device-specific vold
// function that returns the calculated size.
private static final String[] INTERNAL_STORAGE_SIZE_PATHS = {
"/sys/block/mmcblk0/size",
"/sys/block/sda/size"
};
private static final int INTERNAL_STORAGE_SECTOR_SIZE = 512;
private final Context mContext;
private final ContentResolver mResolver;
@@ -926,9 +931,13 @@ public class StorageManager {
/** {@hide} */
public long getPrimaryStorageSize() {
final long numberBlocks = readLong(INTERNAL_STORAGE_SIZE_PATH);
final long sectorSize = readLong(INTERNAL_STORAGE_SECTOR_SIZE);
return numberBlocks * sectorSize;
for (String path : INTERNAL_STORAGE_SIZE_PATHS) {
final long numberBlocks = readLong(path);
if (numberBlocks > 0) {
return numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE;
}
}
return 0;
}
private long readLong(String path) {
@@ -936,7 +945,7 @@ public class StorageManager {
final BufferedReader reader = new BufferedReader(new InputStreamReader(fis));) {
return Long.parseLong(reader.readLine());
} catch (Exception e) {
Slog.w("Could not read " + path, e);
Slog.w(TAG, "Could not read " + path, e);
return 0;
}
}