Merge \"Improved storage size detection.\" into nyc-mr1-dev

am: f0de4da42f

Change-Id: I9794d1d3e15177c88e49911e1b406433025e85c4
This commit is contained in:
Felipe Leme
2016-07-20 19:19:19 +00:00
committed by android-build-merger

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;
}
}