Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f0de4da4 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

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

parents 881bc352 179923a6
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -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;
        }
    }