Merge "Improved storage size detection." into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
f0de4da42f
@@ -132,10 +132,15 @@ public class StorageManager {
|
|||||||
public static final int FLAG_INCLUDE_INVISIBLE = 1 << 10;
|
public static final int FLAG_INCLUDE_INVISIBLE = 1 << 10;
|
||||||
|
|
||||||
private static volatile IMountService sMountService = null;
|
private static volatile IMountService sMountService = null;
|
||||||
private static final String INTERNAL_STORAGE_SIZE_PATH =
|
|
||||||
"/sys/block/mmcblk0/size";
|
// TODO: the location of the primary storage block varies from device to device, so we need to
|
||||||
private static final String INTERNAL_STORAGE_SECTOR_SIZE =
|
// try the most likely candidates - a long-term solution would be a device-specific vold
|
||||||
"/sys/block/mmcblk0/queue/hw_sector_size";
|
// 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 Context mContext;
|
||||||
private final ContentResolver mResolver;
|
private final ContentResolver mResolver;
|
||||||
@@ -926,9 +931,13 @@ public class StorageManager {
|
|||||||
|
|
||||||
/** {@hide} */
|
/** {@hide} */
|
||||||
public long getPrimaryStorageSize() {
|
public long getPrimaryStorageSize() {
|
||||||
final long numberBlocks = readLong(INTERNAL_STORAGE_SIZE_PATH);
|
for (String path : INTERNAL_STORAGE_SIZE_PATHS) {
|
||||||
final long sectorSize = readLong(INTERNAL_STORAGE_SECTOR_SIZE);
|
final long numberBlocks = readLong(path);
|
||||||
return numberBlocks * sectorSize;
|
if (numberBlocks > 0) {
|
||||||
|
return numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private long readLong(String path) {
|
private long readLong(String path) {
|
||||||
@@ -936,7 +945,7 @@ public class StorageManager {
|
|||||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(fis));) {
|
final BufferedReader reader = new BufferedReader(new InputStreamReader(fis));) {
|
||||||
return Long.parseLong(reader.readLine());
|
return Long.parseLong(reader.readLine());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Slog.w("Could not read " + path, e);
|
Slog.w(TAG, "Could not read " + path, e);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user