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

Unverified Commit c0d3f0ed authored by Felipe Leme's avatar Felipe Leme Committed by Alex Naidis
Browse files

Dumps total size of primary storage.

BUG: 32069168
Test: manual verification

(cherry picked from commit 281389ac)

Change-Id: If5dee52a99c03a00dada22736c09d953dc0b66d1
parent bbbe5e6c
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.SparseArray;

@@ -930,22 +931,29 @@ public class StorageManager {
    }

    /** {@hide} */
    public long getPrimaryStorageSize() {
    public static Pair<String, Long> getPrimaryStoragePathAndSize() {
        for (String path : INTERNAL_STORAGE_SIZE_PATHS) {
            final long numberBlocks = readLong(path);
            if (numberBlocks > 0) {
                return numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE;
                return new Pair<>(path, Long.valueOf(numberBlocks * INTERNAL_STORAGE_SECTOR_SIZE));
            }
        }
        return 0;
        return null;
    }


    /** {@hide} */
    public long getPrimaryStorageSize() {
        final Pair<String, Long> pair = getPrimaryStoragePathAndSize();
        return pair == null ? 0 : pair.second.longValue();
    }

    private long readLong(String path) {
    private static long readLong(String path) {
        try (final FileInputStream fis = new FileInputStream(path);
                final BufferedReader reader = new BufferedReader(new InputStreamReader(fis));) {
            return Long.parseLong(reader.readLine());
        } catch (Exception e) {
            Slog.w(TAG, "Could not read " + path, e);
            Slog.w(TAG, "readLong(): could not read " + path + ": " + e);
            return 0;
        }
    }
+14 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.content.pm.ProviderInfo;
import android.content.pm.UserInfo;
import android.content.res.Configuration;
import android.content.res.ObbInfo;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.Binder;
import android.os.DropBoxManager;
@@ -86,6 +87,7 @@ import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.AtomicFile;
import android.util.Log;
import android.util.Pair;
import android.util.Slog;
import android.util.TimeUtils;
import android.util.Xml;
@@ -3738,6 +3740,18 @@ class MountService extends IMountService.Stub

            pw.println();
            pw.println("Primary storage UUID: " + mPrimaryStorageUuid);
            final Pair<String, Long> pair = StorageManager.getPrimaryStoragePathAndSize();
            if (pair == null) {
                pw.println("Internal storage total size: N/A");
            } else {
                pw.print("Internal storage (");
                pw.print(pair.first);
                pw.print(") total size: ");
                pw.print(pair.second);
                pw.print(" (");
                pw.print((float) pair.second / TrafficStats.GB_IN_BYTES);
                pw.println(" GB)");
            }
            pw.println("Force adoptable: " + mForceAdoptable);
            pw.println();
            pw.println("Local unlocked users: " + Arrays.toString(mLocalUnlockedUsers));